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

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

属性解析:

type:动画过渡类型

subtype:动画过渡方向

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

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

代码一:

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)UIImageView *imgView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)];
    [self.view addSubview:self.imgView];
    UIButton *btn1=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@"上一张" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag=1;
    btn1.backgroundColor=[UIColor redColor];
    btn1.frame=CGRectMake(50, 100, 80,40);

    [self.view addSubview:btn1];

    UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:@"下一张" forState:UIControlStateNormal];
    btn2.tag=2;
    [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn2.frame=CGRectMake(150, 100, 80,40);
    btn2.backgroundColor=[UIColor redColor];
    [self.view addSubview:btn2];

}
-(void)btnClick:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    if (btn.tag==1) {
        self.imgView.image=[UIImage imageNamed:@"1.jpg"];
        CATransition *transition=[CATransition animation];
        //动画效果
        transition.type=@"push";
        //动画方向
        transition.subtype=kCATransitionFromRight;
        transition.duration=2.0;
        [self.imgView.layer addAnimation:transition forKey:nil];
    }
    else
    {
        self.imgView.image=[UIImage imageNamed:@"2.jpg"];
        CATransition *transition=[CATransition animation];
        transition.type=kCATransitionMoveIn;
        transition.subtype=kCATransitionFromBottom;
        transition.duration=2.0;
        [self.imgView.layer addAnimation:transition forKey:nil];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@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. CMUSphinx Learn - Before you start

    Before you start 开始之前 Before you start the development of the speech application, you need to consid ...

  2. Anroid 手机助手 详细解析 概述(二)

    这篇主要说一下手机插入之后的一些动作. 1)  捕获窗口消息 插入拔出一个USB设备windows 会给所有的窗口发送特定的消息,只要我们捕获这些消息就可以处理设备插入和拔出.需要注意的是插入或者拔出 ...

  3. poj 1837 01背包

    Balance Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java clas ...

  4. unidbgrid单元格操作

    unidbgrid单元格操作 //GRID里回车替换TABfunction cellkeydown(sender, td, cellIndex, record, tr, rowIndex, e, eO ...

  5. [leetcode 12] Inter to Roman

    1 题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

  6. NW.js安装原生node模块node-printer控制打印机

    1.安装原生node模块 #全局安装nw-gyp npm install -g nw-gyp #设置目标NW.js版本 set npm_config_target=0.31.4 #设置构建架构,ia3 ...

  7. ionic 图片轮播ion-slide-box问题

    1.使用ion-slide可以实现图片轮播,但是如果在html中仅仅增加ion-slide是远远不够的,会出现两个问题: (注:使用的是angularjs.首先需要在,js文件中注入:$ionicSl ...

  8. 浏览器环境下Javascript脚本加载与执行探析之DOMContentLoaded

    在”浏览器环境下Javascript脚本加载与执行探析“系列文章的前几篇,分别针对浏览器环境下JavaScript加载与执行相关的知识点或者属性进行了探究,感兴趣的同学可以先行阅读前几篇文章,了解相关 ...

  9. 常用Java集合类总结

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 7.1.List(允许重复元素) ArrayList: 底层数据结构:Object[] 在查询(get).遍 ...

  10. [Ynoi2019模拟赛]Yuno loves sqrt technology II(二次离线莫队)

    二次离线莫队. 终于懂了 \(lxl\) 大爷发明的二次离线莫队,\(\%\%\%lxl\) 二次离线莫队,顾名思义就是将莫队离线两次.那怎么离线两次呢? 每当我们将 \([l,r]\) 移动右端点到 ...