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 ...
随机推荐
- 关于iOS路径变化的解决方案
问题描述: 使用沙盒存储文件的时候,我们会保存文件的绝对路劲以便下次读取,但是发现一个现象,我们保存的文件,在第二次打开App去查找的时候,发现找不到了...... 查找原因: iOS8之后,苹果添加 ...
- Java基础教程——结构化编程
结构化编程 各结构的图示请参见: https://www.cnblogs.com/tigerlion/p/10703926.html 选择结构 |-if:如果 |-else:其他:此外:否则. pub ...
- 生僻的mysql
1.show table status like 'user' 2.alter table mytableEngine=InnoDB 需要执行很长时间,mysql会按行将数据从原表复制到一张新的表中, ...
- CentOS基础命令使用技巧-1
less用法 g快速返回文件首部 G快速到文本最末端 /当前行向下搜索 ?当前行向上搜索 n显示下一个 q退出 cp用法 r拷贝一个目录必须加这个 rm用法 r删除目录 f强制删除,r后面删除不存在的 ...
- Alpha冲刺-第三次冲刺笔记
Alpha冲刺-冲刺笔记 这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE2 这个作业要求在哪里 https://edu.cnblogs. ...
- 自学linux——20.Samba服务器的搭建
Samba服务器的搭建 一.Samba的认识 1.Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件 2.Samba不仅用于Linux与windows系统直接的文件共享和打印共 ...
- 什么是Python迭代器?
迭代器(Iterator):迭代器可以看作是一个特殊的对象,每次调用该对象时会返回自身的下一个元素,从实现上来看,一个迭代器对象必须是定义了__iter__()方法和next()方法的对象. Pyth ...
- PyQt(Python+Qt)学习随笔:复选框状态枚举类Qt.CheckState取值及含义
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 老猿Python,跟老猿学Python! 老猿Python博文目录 专栏:使用PyQt开发图形界面P ...
- Springboot集成xxl-Job
一.前言 xxl-job一个轻量级的分布的调度中间件,详情介绍自己到官网看:https://www.xuxueli.com/xxl-job/ 二.客户端(执行器) 引入依赖compile group: ...
- Proxy:简单小巧又强大好用的代理系统
之前的文章介绍了许多我们在用的DevOps相关的工具系统,例如:方便创建多套运行环境的Alodi,对运维友好的配置中心Kerrigan,强大的自定义任务引擎Probius以及专注于数据库自动化的ove ...