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 ...
随机推荐
- 自定义 JSTLFunction
复习常用JSTL Function为什么需要自定义Function如何自定义Function,例子:1.在独立的项目中(也可以在web项目中)的类中(比如Functions)编写一个static方法: ...
- Windows下创建指定大小的文件
前言 因为需要测试存储容量,所以需要能生成指定大小的文件. 执行 #语法:fsutil file createnew 路径和文件名 文件大小 fsutil file createnew D:\test ...
- Java基础教程——正则表达式
正则表达式·Regular Expression 正则表达式就是一个用于匹配字符串的模板,正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别. 主要用到的对象: java.util.rege ...
- IPSec传输模式/隧道模式下ESP报文的装包与拆包过程
IPSec协议:IPsec将IP数据包的内容先加密再传输,即便中途被截获,由于缺乏解密数据包所必要的密钥,攻击者也无法获取里面的内容. 传输模式和隧道模式:IPsec对数据进行加密的方式有两种:传输模 ...
- sqli-labs-master less01
注:如未接触过sql注入,建议观看前期知识点文章 https://www.cnblogs.com/yyd-sun/p/12256407.html 第一关步骤 一.判断注入类型(数字/字符) (1).h ...
- C#(二)基础篇—操作符
2020-12-02 本随笔为个人复习巩固知识用,多从书上总结与理解得来,如有错误麻烦指正 1.数学操作符 int a=2,b=3,c=0; float d=0; c=a+b; //c=5 c++; ...
- MongoEngine模块
今儿,接到老的的要求,要把新功能的数据存放在Mongo里.虽然一直都有听过Mango的鼎鼎大名,但是那也只是见过没用过,跟个小白没啥区别.在加上功能急需,没办法只能赶鸭子上架先上再说.下面这篇就是我赶 ...
- 大数据技术体系 && NoSQL数据库的基本原理
1.NoSQL产生的原因 目前关系型数据库难以应对日益增多的海量数据,横向的分布式扩展能力比较弱,因此构建出非关系型数据库(所谓的NoSQL),其目的是为了构建一种结构简单.分布式.易扩展.效率高且使 ...
- 补:冲刺Day2
每天举行站立式会议照片: 昨天已完成的工作: 各个成员在 Alpha 阶段认领的任务. 今天各个成员的任务安排. 冲刺Day1博客. 今天计划完成的工作: 成员 任务 高嘉淳 完成登陆.注册 覃泽泰 ...
- 使用 open 函数 写的代码 用户名登录
先创建文件ha.log 内容: aaa$$123bbb$$456 def dl(user,pas): f = open('ha.log', 'r', encoding="utf-8" ...