用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点

UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果

属性解析:

type:动画过渡类型

subtype:动画过渡方向

startProgress:动画起点(在整体动画的百分比)

endProgress:动画终点(在整体动画的百分比)

代码一:

  1. #import "ViewController.h"
  2.  
  3. @interface ViewController ()
  4. @property(nonatomic,strong)UIImageView *imgView;
  5. @end
  6.  
  7. @implementation ViewController
  8.  
  9. - (void)viewDidLoad {
  10. [super viewDidLoad];
  11.  
  12. self.imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];
  13. [self.view addSubview:self.imgView];
  14. UIButton *btn1=[UIButton buttonWithType:UIButtonTypeCustom];
  15. [btn1 setTitle:@"上一张" forState:UIControlStateNormal];
  16. [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  17. btn1.tag=1;
  18. btn1.backgroundColor=[UIColor redColor];
  19. btn1.frame=CGRectMake(50, 100, 80,40);
  20.  
  21. [self.view addSubview:btn1];
  22.  
  23. UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom];
  24. [btn2 setTitle:@"下一张" forState:UIControlStateNormal];
  25. btn2.tag=2;
  26. [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  27. btn2.frame=CGRectMake(150, 100, 80,40);
  28. btn2.backgroundColor=[UIColor redColor];
  29. [self.view addSubview:btn2];
  30.  
  31. }
  32. -(void)btnClick:(id)sender
  33. {
  34. UIButton *btn=(UIButton *)sender;
  35. if (btn.tag==1) {
  36. self.imgView.image=[UIImage imageNamed:@"1.jpg"];
  37. CATransition *transition=[CATransition animation];
  38. //动画效果
  39. transition.type=@"push";
  40. //动画方向
  41. transition.subtype=kCATransitionFromRight;
  42. transition.duration=2.0;
  43. [self.imgView.layer addAnimation:transition forKey:nil];
  44. }
  45. else
  46. {
  47. self.imgView.image=[UIImage imageNamed:@"2.jpg"];
  48. CATransition *transition=[CATransition animation];
  49. transition.type=kCATransitionMoveIn;
  50. transition.subtype=kCATransitionFromBottom;
  51. transition.duration=2.0;
  52. [self.imgView.layer addAnimation:transition forKey:nil];
  53. }
  54.  
  55. }
  56.  
  57. - (void)didReceiveMemoryWarning {
  58. [super didReceiveMemoryWarning];
  59. // Dispose of any resources that can be recreated.
  60. }
  61.  
  62. @end

代码二:

core Animation之CATransition(转场动画)的更多相关文章

  1. CATransition转场动画

    背景: 最近在温习动画,分享个简单系统的转场动画 viewcontroller *VC=[self.storyboard instantiateViewControllerWithIdentifier ...

  2. 之四:CATransition - 转场动画

    关键属性: type 过渡效果  kCATransitionFade  淡出 kCATransitionMoveIn  覆盖原图 kCATransitionPush  推出 kCATransition ...

  3. CATransition 转场动画解析

    http://blog.csdn.net/mad2man/article/details/17260901

  4. iOS开发基础知识:Core Animation(核心动画)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能. Core A ...

  5. iOS之核心动画(Core Animation)

      Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能. Core ...

  6. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  7. iOS动画-从UIView到Core Animation

    首先,介绍一下UIView相关的动画. UIView普通动画: [UIView beginAnimations: context:]; [UIView commitAnimations]; 动画属性设 ...

  8. iOS开发 - Core Animation 核心动画

    Core Animation Core Animation.中文翻译为核心动画,它是一组很强大的动画处理API,使用它能做出很炫丽的动画效果.并且往往是事半功倍. 也就是说,使用少量的代码就能够实现很 ...

  9. iOS - Core Animation(核心动画)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能.Core An ...

随机推荐

  1. NODE-WEBKIT教程(5)NATIVE UI API 之FRAMELESS WINDOW

    node-webkit教程(5)Native UI API 之Frameless window 文/玄魂 原文链接:http://www.xuanhun521.com/Blog/2014/4/15/n ...

  2. openvSwitch 基本命令

    建立ovs接口连接两个namespace组成二层网络 环境搭建拓扑 br0 +--------------------------------------+ +--+ +--+ +---+ | tap ...

  3. 使用Samba实现文件共享

    1987年,微软公司和英特尔公司,共同制定了SMB(Server Messages Block 服务消息块)协议,指在解决局域网内的文件或打印机等资源的共享问题,这也使得在多个主机之间共享文件变得越来 ...

  4. 2018 Multi-University Training Contest 6

    A.oval-and-rectangle 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6362 题意:在长半轴为a,短半轴为b的椭圆内部,以y=c( ...

  5. HDU - 2604 Queuing(递推式+矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. 读配置文件property文件

    import java.io.IOException;import java.util.Properties; import org.springframework.core.io.support.P ...

  7. drf-序列化器的理解

    序列化器作用:  1.进行数据的校验 2.对数据对象进行转换 序列化:  模型类对象  ----->  python字典    用于输出, 返回给前端使用 反序列化:  前端传送的数据  --- ...

  8. B2C电商项目

    经历四个月的自学. 结合所学的知识(HTML,CSS,javascript,jQuery,Mysql,Redis,Django,celery,fastDfs,haystack,whoosh,uWSGI ...

  9. 同时绑定onpropertychange 和 oninput 事件,实时检测 input、textarea输入改变事件,支持低版本IE,支持复制粘贴

    实时检测 input.textarea输入改变事件,支持低版本IE,支持复制粘贴 检测input.textarea输入改变事件有以下几种: 1.onkeyup/onkeydown 捕获用户键盘输入事件 ...

  10. Hive中的Row_Number()使用

    语法:row_number() over (partition by 字段a order by 计算项b desc ) rank --这里rank是别名 partition by:类似hive的建表, ...