Core Animation之CATransition和CAAnimationGroup

Core Animation之CATransition和CAAnimationGroup

CATransition

  • CATransition是CAAnimation的子类,用于做转场动画
  • 能为层提供移除屏幕和移入屏幕的动画效果
  • UINavigationController就是通过CATransition实现了将控制器的试图推入屏幕的动画效果
转场动画的属性
  • type:过渡类型
  • subtype:过渡方向
  • startProgress:动画起点(在整体动画的百分比)
  • endProgress:动画终点(在整体动画的百分比)
    CATransition *anim = [CATransition animation];
    anim.type = @"cube";
    anim.subtype = kCATransitionFromLeft;
    anim.duration = 0.5;
    [_imageView.layer addAnimation:anim forKey:nil];

CAAnimationGroup

  • 动画组也是CAAnimation的子类,可以保存一组动画对象
  • CAAnimationGroup对象加入层之后,组中所有动画可以同时并发执行
动画组属性
  • animations:用来保存一组动画对象的NSArray
  • beginTime:动画对象的开始时间。默认是同时运行的
// 旋转
    CABasicAnimation *rotation = [CABasicAnimation animation];

    rotation.keyPath = @"transform.rotation";

    rotation.toValue = @M_PI_2;

    // 位移
    CABasicAnimation *position = [CABasicAnimation animation];

    position.keyPath = @"position";

    position.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 250)];

    // 缩放
    CABasicAnimation *scale = [CABasicAnimation animation];

    scale.keyPath = @"transform.scale";

    scale.toValue = @0.5;

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.animations = @[rotation,position,scale];

    group.duration = 2;

    // 取消反弹
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;

    [_redView.layer addAnimation:group forKey:nil];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 文 || 張贺 Core Animation简介 Core Animation,中文翻译为核心动画,它是一组非常强...
    張贺阅读 2,067评论 9 35
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,159评论 1 23
  • 一、简介 Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽...
    莦婼姑娘阅读 980评论 0 4
  • 核心动画的基本结构 CAAnimation 是个虚类 不能直接使用 继承之下有三个子类 CAAnimationG...
    藤王俊采阅读 423评论 1 2
  • Core Animation 核心动画 Core Animation是一组非常强大的动画处理API,使用它能做出非...
    iOS_Cqlee阅读 2,327评论 0 8