iOS UIcollectionView 实现卡牌翻转效果
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = @"卡牌翻转效果";
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.view addSubview:self.collectionView];
NSArray * arr = @[@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0",@"0"];
[arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Model *model =[[Model alloc] init];
model.select = [obj boolValue];
[self.dataArray addObject:model];
}];
[self.collectionView reloadData];
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
-(UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
// 定义大小
layout.itemSize = CGSizeMake((appWidth - 40)/2.0, 0.8*(appWidth - 40)/2.0);
// 设置最小行间距
layout.minimumLineSpacing = 10;
// 设置垂直间距
layout.minimumInteritemSpacing = 10;
layout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
// 设置垂直间距
layout.headerReferenceSize = CGSizeMake(0, 0);
// 设置滚动方向(默认垂直滚动)
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, appWidth, appHeight - 64) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"homeCell"];
}
return _collectionView;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
HomeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"homeCell" forIndexPath:indexPath];
Model * model = self.dataArray[indexPath.item];
if (model.select == YES) {
cell.secondView.hidden = YES;
cell.firstview.hidden = NO;
}else{
cell.secondView.hidden = NO;
cell.firstview.hidden = YES;
}
cell.bt.tag = indexPath.item;
[cell.bt addTarget:self action:@selector(didBtAction:event:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
Model* model = self.dataArray[indexPath.item];
HomeCollectionViewCell * cell1 = (HomeCollectionViewCell *)cell;
if (model.select == YES) {
cell1.secondView.hidden = YES;
cell1.firstview.hidden = NO;
}else{
cell1.secondView.hidden = NO;
cell1.firstview.hidden = YES;
}
}
- (void)didBtAction:(UIButton *)sender event:(UIEvent *)event{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint position = [touch locationInView:self.collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:position];
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
HomeCollectionViewCell *cell = (HomeCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
//这里时查找视图里的子视图(这种情况查找,可能时因为父视图里面不只两个视图)
// NSInteger fist= [[cell subviews] indexOfObject:[cell viewWithTag:1000]];
// NSInteger seconde= [[cell subviews] indexOfObject:[cell viewWithTag:2000]];
Model* model = self.dataArray[indexPath.item];
// 3、3D翻转动画
[UIView animateWithDuration:1.0 animations:^{
if (model.select == YES)
{
cell.secondView.hidden = NO;
cell.firstview.hidden = YES;
model.select = NO;
[self.dataArray replaceObjectAtIndex:indexPath.item withObject:model];// 当前显示的是正面视图
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:cell cache:YES];
}
else
{
cell.secondView.hidden = YES;
cell.firstview.hidden = NO;
model.select = YES;
[self.dataArray replaceObjectAtIndex:indexPath.item withObject:model];// 当前显示的是背面视图
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell cache:YES];
}
}];
}
iOS UIcollectionView 实现卡牌翻转效果的更多相关文章
- CCOrbitCamera卡牌翻转效果
static CCOrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngl ...
- cocos2d-x 卡牌翻牌效果的实现
转自:http://blog.csdn.net/yanghuiliu/article/details/9115833 这个能实现翻牌的action就是CCOrbitCamera. static CCO ...
- TCG卡牌游戏研究:《炉石战记:魔兽英雄传》所做的改变
转自:http://www.gameres.com/665306.html TCG演进史 说到卡牌游戏,大家会联想到什么呢? 是历史悠久的扑克牌.风靡全球的<MTG 魔法风云会>与< ...
- Unity3D_(游戏)卡牌04_游戏界面
启动屏界面.主菜单界面.选关界面.游戏界面 卡牌01_启动屏界面 传送门 卡牌02_主菜单界面 传送门 卡牌03_选关界面 传送门 卡牌04_游戏界面 传送门 选关界面效果 (源代码在文 ...
- 使用UIKit制作卡牌游戏(三)ios游戏篇
译者: Lao Jiang | 原文作者: Matthijs Hollemans写于2012/07/13 转自朋友Tommy 的翻译,自己只翻译了这第三篇教程. 原文地址: http://www.ra ...
- css3实现卡牌旋转与物体发光效果
效果演示 http://demo.qpdiy.com/hxw/CSS3/rotate+light.html 物体旋转: 卡牌同一位置放2张图片,通过设置3D动画旋转实现 animation: card ...
- iOS中UIView翻转效果实现
本文转载至 http://baishiyun.blog.163.com/blog/static/13057117920148228261747/ 新建一个view-based模板工程,在ViewCo ...
- 在WebGL场景中管理多个卡牌对象的实验
这篇文章讨论如何在基于Babylon.js的WebGL场景中,实现多个简单卡牌类对象的显示.选择.分组.排序,同时建立一套实用的3D场景代码框架.由于作者美工能力有限,所以示例场景视觉效果可能欠佳,本 ...
- 解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题
解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题 div{ width: 100%; overflow-y: hidden; -webkit-o ...
随机推荐
- 宝塔Linux面板安装
宝塔linux6.0版本是基于centos7开发的,务必使用centos7.x 系统 提示:Centos官方已宣布在2020年停止对Centos6的维护更新,各大软件开发商也逐渐停止对Centos6的 ...
- Codeforces Round #670 (Div. 2) D. Three Sequences 题解(差分+思维+构造)
题目链接 题目大意 给你一个长为n的数组a,要你构造一个非严格单调上升的数组b和一个非严格单调下降的数组c,使得\(b_i+c_i=a_i\) 要你使这两个数组b,c中最大的元素最小,还有q次修改(q ...
- 企业安全03Django GIS SQL注入漏洞CVE-2020-9402
Django GIS SQL注入漏洞CVE-2020-9402 一.漏洞描述 Django是Django基金会的一套基于Python语言的开源Web应用框架.该框架包括面向对象的映射器.视图系统.模板 ...
- java数组作为函数返回值
1 //将一个二维数组行和列元素互换.存到另一个二维数组 2 package test; 3 4 public class test1_8 { 5 public static int[][] huhu ...
- limit+orderBy陷阱
碰到一个奇怪的bug,在排序的时候对一个非唯一的字段做order by, 结果在分页的时候,发现每一页的数据都是乱的,并不是对整个排序之后再去limit的. 当我们用唯一字段去排序的时候,因为在找到满 ...
- dubbo协议之请求头编码器
开局一张图,内容全靠XXXXX.... 如图是dubbo协议的格式 encodeRequest进来会先去channel对象中取url的Parameters的"serialization&qu ...
- Spring与Web环境集成
1. Spring与Web环境集成 1.1 ApplicationContext应用上下文获取方式 应用上下文对象是通过new ClasspathXmlApplicationContext(sprin ...
- Windows生产力工具推荐
相信大部分同学还是Windows用户,作为一个长期Windows/MacOS双系统长期用户,Windows在用的好,工作效率也很高,下面就推荐几款Windows下面的生产力工具. utools 用过M ...
- LeetCode 刷题总结
LeetCode上的题很不错,都短小精悍. 先说说我自己.本科一直都是偏硬件,做些单片机.FPGA的东西.本科毕业设计写了个Android APP,控制外围电路(一个小车).可以通过Android手机 ...
- DRAM三种刷新方式(转载)
设DRAM中电容的电荷每2ms就会丢失,所以2ms内必须对其补充.补充电荷是按行来进行的,为了[全部]内存都能保住电荷,必须对[所有]的行都得补充. 假设刷新1行的时间为0.5μs(刷新时间是等于存取 ...