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 ...
随机推荐
- Java蓝桥杯练习——杨辉三角形
问题描述: 杨辉三角形又称Pascal三角形,它的第i+1行是(a+b)i的展开式的系数. 它的一个重要性质是:三角形中的每个数字等于它两肩上的数字相加. 下面给出了杨辉三角形的前4行: 1 1 1 ...
- Java反射说得透彻一些
目录 一.反射机制是什么? 二.反射的具体使用 2.1 获取对象的包名以及类名 2.2 获取Class对象 2.3 getInstance()获取指定类型的实例化对象 2.4 通过构造函数对象实例化对 ...
- JVM 堆中对象分配、布局和访问
本文摘自深入理解 Java 虚拟机第三版 对象的创建 Java 是一门面向对象的语言,Java 程序运行过程中无时无刻都有对象被创建出来.从语言层面看,创建对象只是一个 new 关键字而已,而在虚拟机 ...
- 数据库事务ACID/隔离级别
参考博客 1. 事务的定义 事务是用户定义的一个数据库操作序列.这些操作要么全执行,要么全不执行,是一个不可分割的工作单元.在关系型数据库中,事务可以是一条SQL语句,也可以是一组SQL语句或整个程序 ...
- Mysql-索引分析查询性能
explain 全文只有一个关键点,那就是explain,explain 显示了MySQL如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句.简单讲,它的作用就 ...
- PyQt(Python+Qt)学习随笔:QDockWidget停靠部件的dockWidgetArea和docked属性
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 dockWidgetArea和docked属性这两个属性在Design ...
- Python中的文档字符串作用
文档字符串是使用一对三个单引号 ''' 或者一对三个双引号 """来包围且没有赋值给变量的一段文字说明(如果是单行且本身不含引号,也可以是单引号和双引号), 它在代码执行 ...
- ATT&CK 实战 - 红日安全 vulnstack (一) 环境部署
靶场描述: 红队实战系列,主要以真实企业环境为实例搭建一系列靶场,通过练习.视频教程.博客三位一体学习.另外本次实战完全模拟ATT&CK攻击链路进行搭建,开成完整闭环.后续也会搭建真实APT实 ...
- 大数据技术体系 && NoSQL数据库的基本原理
1.NoSQL产生的原因 目前关系型数据库难以应对日益增多的海量数据,横向的分布式扩展能力比较弱,因此构建出非关系型数据库(所谓的NoSQL),其目的是为了构建一种结构简单.分布式.易扩展.效率高且使 ...
- 敏捷开发(Scrum)与敏捷测试
1.敏捷测试流程和传统测试流程 软件测试是贯穿整个软件开发生命周期.对软件产品(包括阶段性产品)进行验证和确认的活动过程,也是对软件产品质量持续的评估过程,其目的是尽快尽早地发现在软件产品(包括阶段性 ...