IOS 动画 核心动画之转场动画CATransition

来源:互联网 发布:java工程师岗位 编辑:程序博客网 时间:2024/04/30 20:21

1.先看下效果
这里写图片描述

步骤:

  1. 修改转场后的图片
  2. 生成并设置转场动画对象(CATransition)
  3. layer添加动画

看下基本的实现代码:

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    index++;    self.imageView.image=[UIImage imageNamed:index%2==0?@"2":@"1"];//先设置转场后的图片    CATransition *ca=[CATransition animation];//1初始化CATransition    ca.type=typeArry[index%6];//设置动画的类型    ca.duration=2;//动画时间    [self.imageView.layer addAnimation:ca forKey:nil];//layer添加动画}

其中主要的是转场的过渡动画类型(copy下)
CATransition的type属性

1.#define定义的常量
kCATransitionFade 交叉淡化过渡
kCATransitionMoveIn 新视图移到旧视图上面
kCATransitionPush 新视图把旧视图推出去
kCATransitionReveal 将旧视图移开,显示下面的新视图

2.用字符串表示
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果

比如想要水滴的效果

ca.type=@"rippleEffect";

还可以设置动画过渡的方向

//看下属性先/* An optional subtype for the transition. E.g. used to specify the * transition direction for motion-based transitions, in which case * the legal values are `fromLeft', `fromRight', `fromTop' and * `fromBottom'. */@property(nullable, copy) NSString *subtype;//使用ca.subtype=@"fromRight";//默认是fromLeft
0 0
原创粉丝点击