objective-c 转场动画
2015-12-22 00:00
489 查看
ViewController.文件
// // ViewController.m // 转场动画 // // Created by DC017 on 15/12/22. // Copyright © 2015年 DC017. All rights reserved. // #import "ViewController.h" #define W [UIScreen mainScreen].bounds.size.width #define H [UIScreen mainScreen].bounds.size.height #define YANSE(r,g,b,a) [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:a] //设置layer的宽和高 #define LayerWidth 50 #define TUPIANSHULIANG 6 @interface ViewController () { int tupianshuliang; UIImageView * image; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; tupianshuliang=0; [self layout]; } -(void)layout{ //定义一个图片控件 image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, W, H)]; image.contentMode=UIViewContentModeScaleToFill; image.image=[UIImage imageNamed:@"0"]; [self.view addSubview:image]; //添加手势 UISwipeGestureRecognizer * leftSwipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(zuo:)]; //设置手势方向 leftSwipeGesture.direction=UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:leftSwipeGesture]; //添加手势 UISwipeGestureRecognizer * congzuoxiangyou=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(you:)]; //设置手势方向 congzuoxiangyou.direction=UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:congzuoxiangyou]; } -(void)zuo:(UISwipeGestureRecognizer *)gesture{ NSLog(@"从右往左滑"); [self transitionAnimation:YES];//表示下一张图片 } -(void)you:(UISwipeGestureRecognizer *)gesture{ NSLog(@"从左向右滑"); [self transitionAnimation:NO];//表示上一张图片 } #pragma mark 转场动画 -(void)transitionAnimation:(BOOL)zhi{ //创建动画对象 CATransition * transactionII=[[CATransition alloc]init]; //设置转场动画 transactionII.type=@"cube"; //设置动画类型,对于苹果官方没有公开的动画类型,只能使用字符串 //cube 立方体翻转效果 //oglFlip 翻转效果 //suckEffect 收缩效果 //rippleEffect 水滴波纹效果 //pageCurl 向上翻页效果 //pageUnCurl 向下翻页效果 //cameraIrisHollowOpen 摄像头打开效果 //cameraIrisHollowClose 摄像头关闭效果 //设置子类型(转场动画从什么方向) if (zhi) { transactionII.subtype=kCATransitionFromRight; }else{ transactionII.subtype=kCATransitionFromLeft; } //设置动画时间 transactionII.duration = 1.0; //设置转场后的新视图 if (zhi) { //下一张 tupianshuliang=(tupianshuliang+1)%TUPIANSHULIANG; }else{ //上一张 tupianshuliang=(tupianshuliang-1 +TUPIANSHULIANG)%TUPIANSHULIANG; } image.image=[UIImage imageNamed:[NSString stringWithFormat:@"%i",tupianshuliang]]; //添加动画 [image.layer addAnimation:transactionII forKey:@"wodedonghau"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- OBjective-c 弹簧效果
- objective-c 逐帧动画
- Object-C 一些关键字的理解 @synchronized、__block、class等。。。
- “object name conflicts in archive”的解决办法
- Mybatis3源码分析(12)-Sql解析执行-MetaObject
- 【Objective-C学习记录】第二十天
- Android中两个activity之间传递list<object>
- 关于Objective-C 错误代码 Expression is not assignable 引发的问题
- Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks程序(Python)配置问题总结
- Objective-c语言_协议
- Objective-c语言_延展
- Objective-c语言_类目
- dYSM分析崩溃日志
- #Objective - C - Fifth-Day 三大容器(数组、字典、集合)常用语法归纳总结
- JAVA 1.6源码解析-Object类
- The constness of a method should makes sense from outside the object
- Informatica Connection Objects
- Objective-c语言_文件基本操作
- Java基础系列六、IDE+Object+String
- 使用 SWFObject.js 插入Flash