CAAnimtion子类_CATransition动画

转场动画 CATransition: CAAnimation的子类 , 用来做转场动画, 能够为layer层提供移除屏幕和移入屏幕的动画效果
  1. 动画属性
    1.1 type: 动画的过度效果
    1.2 subType: 动画的过度方向
    1.3 startProgress: 动画起点(在整体动画的百分比上)
    1.4 endProgress: 动画终点(在整体动画的百分比上)

  2. type属性的值:

Type.png

具体实现实例:

#import "ThreeViewController.h"

@interface ThreeViewController ()
//设置属性
@property (strong, nonatomic) UIView *myView;

@end

@implementation ThreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.myView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-64)];
    
    self.myView.backgroundColor = [UIColor colorWithRed:1.000 green:0.678 blue:0.736 alpha:1.000];
    
    [self.view addSubview:self.myView];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
#pragma mark ------ CATransition -------
    //1. 创建对象
    CATransition *transition = [CATransition animation];
    
    //2. 动画效果
    //@"cube"  @"oglFlip" @"pageUnCurl" 上面附图给出type的值
    transition.type = @"cube";
    
    //3. 动画的开始位置0 ~ 1(按屏幕比例划分)
    transition.startProgress = 0;
    
    //4. 动画的结束位置0 ~ 1
    transition.endProgress = 1;
    
    //5. 动画重复次数
    transition.repeatCount = 3;
    
    //6. 动画的持续时间
    transition.duration = 3;
    
    //7. 动画的方向
    transition.subtype = kCATransitionFromLeft;
    
    //8. 添加到layer层上
    [self.myView.layer addAnimation:transition forKey:@"transitiong"];
    
}

@end```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容