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];