- (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 实现卡牌翻转效果的更多相关文章

  1. CCOrbitCamera卡牌翻转效果

    static CCOrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngl ...

  2. cocos2d-x 卡牌翻牌效果的实现

    转自:http://blog.csdn.net/yanghuiliu/article/details/9115833 这个能实现翻牌的action就是CCOrbitCamera. static CCO ...

  3. TCG卡牌游戏研究:《炉石战记:魔兽英雄传》所做的改变

    转自:http://www.gameres.com/665306.html TCG演进史 说到卡牌游戏,大家会联想到什么呢? 是历史悠久的扑克牌.风靡全球的<MTG 魔法风云会>与< ...

  4. Unity3D_(游戏)卡牌04_游戏界面

        启动屏界面.主菜单界面.选关界面.游戏界面 卡牌01_启动屏界面 传送门 卡牌02_主菜单界面 传送门 卡牌03_选关界面 传送门 卡牌04_游戏界面    传送门 选关界面效果 (源代码在文 ...

  5. 使用UIKit制作卡牌游戏(三)ios游戏篇

    译者: Lao Jiang | 原文作者: Matthijs Hollemans写于2012/07/13 转自朋友Tommy 的翻译,自己只翻译了这第三篇教程. 原文地址: http://www.ra ...

  6. css3实现卡牌旋转与物体发光效果

    效果演示 http://demo.qpdiy.com/hxw/CSS3/rotate+light.html 物体旋转: 卡牌同一位置放2张图片,通过设置3D动画旋转实现 animation: card ...

  7. iOS中UIView翻转效果实现

    本文转载至  http://baishiyun.blog.163.com/blog/static/13057117920148228261747/ 新建一个view-based模板工程,在ViewCo ...

  8. 在WebGL场景中管理多个卡牌对象的实验

    这篇文章讨论如何在基于Babylon.js的WebGL场景中,实现多个简单卡牌类对象的显示.选择.分组.排序,同时建立一套实用的3D场景代码框架.由于作者美工能力有限,所以示例场景视觉效果可能欠佳,本 ...

  9. 解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题

    解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题 div{ width: 100%; overflow-y: hidden; -webkit-o ...

随机推荐

  1. HMM、CTC、RNN-T训练是所有alignment的寻找方法

    1.1 LAS产生label的计算   LAS是可以看做能够直接计算给定一段acoustic feature时输出token sequences的概率,即\(p(Y|X)\),LAS每次给定一个aco ...

  2. 15.java设计模式之访问者模式

    基本需求: 电脑需要键盘鼠标等固定的组件组成 现在分为个人,组织等去买电脑,而同一种组件对不同的人(访问者)做出不同的折扣,从而电脑的价格也不一样 传统的解决方法:在组件内部进行判断访问人的类型,从而 ...

  3. E - Knapsack 2 题解(超大01背包)

    题目链接 题目大意 给你一n(n<=100)个物品,物品价值最大为1e3,物品体积最多为1e9,背包最大为1e9 题目思路 如果按照平常的背包来算那么时间复杂度直接O(1e11) 这个你观察就发 ...

  4. 使用zabbix监控Jenkins

    一.监控架构图 二.实现思路 在 Jenkins 上安装 Metrics 插件,使 Jenkins 暴露 metrics api: 编写python代码从api抓取数据,并将数据解析为zabbix可以 ...

  5. [原理] Android Native内存泄漏检测原理解析

    转载请注明出处:https://www.cnblogs.com/zzcperf/articles/11615655.html 上一篇文章列举了不同版本Android OS内存泄漏的检测操作(传送门), ...

  6. CentOS 7搭建本地yum源

    问题 CentOS7.1安装rpm包时提示缺失包,有些包iso里面也没有,只能从外网yum,这种情况下,可以提前yum好所需的依赖包,做成一个本地yum源.将这些文件拷贝到没联网的机器就可以使用了. ...

  7. 第9章 Python文件操作目录

    第9章 Python文件操作 第9.1节 Python的文件打开函数open简介 第9.2节 Python的文件打开函数open详解 第9.3节 Python的文件行读取:readline 第9.4节 ...

  8. Python爬虫学习遇到的问题

    老猿在学习Python中爬虫知识时遇到了如下问题: 爬取网页内容后写入文件报错UnicodeEncodeError: 'gbk' codec can't encode的问题解决方案 urllib.re ...

  9. PyQt(Python+Qt)学习随笔:Qt Designer中部件的是否接受鼠标拖放事件的acceptDrops属性及含义

    acceptDrops属性表示当前部件是否接受鼠标拖放事件,鼠标拖放应该是与鼠标拖拽结合在一起的,在Qt Designer中可以通过属性acceptDrops设置部件是否接受鼠标拖放事件.如果部件接受 ...

  10. ADF 第一篇:Azure Data Factory介绍

    Azure Data Factory(简写 ADF)是Azure的云ETL服务,简单的说,就是云上的SSIS.ADF是基于云的ETL,用于数据集成和数据转换,不需要代码,直接通过UI(code-fre ...