- (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. 课时一:JS操作数据

    课时一:JS操作数据 JSAPI请求头 xmlhttp.setRequestHeader("Content-Type", "application/json; chars ...

  2. 02_启动和销毁Service

    在Application关闭后,Service仍然会运行. package com.example.servdemo; import android.app.Activity; import andr ...

  3. Django的路由分发与名称空间

    路由分发 django每一个app下面都可以有自己的urls.py路由层,templates文件夹,static文件夹 项目名下urls.py(总路由)不再做路由与视图函数的匹配关系而是做路由的分发 ...

  4. Fiddler 4 (利用Fiddler模拟恶劣网络环境)

    1.模拟弱网环境 打开Fiddler,Rules->Performance->勾选 Simulate Modem Speeds,勾选之后访问网站会发现网络慢了很多 解决办法去掉勾选的地方网 ...

  5. AlanShan数据库课程设计报告

    目    录 1.绪论.... 2 1.1前言... 2 1.2社会背景... 2 1.3超市背景... 3 2.系统可行性研究.... 4 2.1 技术可行性研究... 4 2.2 经济可行性研究. ...

  6. c++11-17 模板核心知识(十三)—— 名称查找与ADL

    名称分类 名称查找 ordinary lookup ADL (Argument-Dependent Lookup) 官网的例子 ADL的缺点 在C++中,如果编译器遇到一个名称,它会寻找这个名称代表什 ...

  7. 使用 webpack 手动搭建 vue 项目

    webpack 是一个前端工程化打包工具,对于前端工程师来说 webpack 是一项十分重要的技能.下面我们就通过搭建一个 vue 项目来学习使用 webpack 主要环境: node v14.15. ...

  8. upload 注意php远程安全模式屏蔽函数

    进来:上传一个一句话php,果然不行:改成jpg后缀,上传成功:接着写一个.htaccess文件去把.jpg解析成.php,如下: AddType application/x-httpd-php .j ...

  9. XSS挑战赛(2)

    进入第六关 简单判断过滤情况 <>script"'/ 查看源代码 可以看到第二个红框部分跟之前类似,闭合双引号尝试进行弹窗 "><script>ale ...

  10. go中位运算

    左移右移 const ( // 将 1 左移 100 位来创建一个非常大的数字 // 即这个数的二进制是 1 后面跟着 100 个 0 Big = 1 << 100 // 再往右移 99 ...