- Core Animation是可以用在Mac OS X 和iOS平台的
- 动画的执行是在后台操作的,不会阻塞主线程
- 直接作用在CALayer,而不是UIVIew

image.png
CAKeyframeAnimation
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"position";
//贝塞尔曲线
UIBezierPath *path = [UIBezierPath bezierPath];
//起点
[path moveToPoint:CGPointMake(50, 50)];
//连线
[path addLineToPoint:CGPointMake(300, 50)];
anim.duration = 0.5;
//动画保持最后一个状态
anim.fillMode = kCAFillModeForwards;
anim.path = path.CGPath;
//动画执行完不会被自动删除
anim.removedOnCompletion = NO;
[self.imageV.layer addAnimation:anim forKey:nil];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"transform.rotation";
anim.values = @[@angleZRad(-5),@angleZRad(5)];
//自动反转
anim.autoreverses = YES;
anim.repeatCount = MAXFLOAT;
[self.imageV.layer addAnimation:anim forKey:nil];
CABasicAnimation
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform.scale";
anim.toValue = @0;
anim.duration = 1;
//设置自动反转
anim.autoreverses = YES;
//设置动画无线执行
anim.repeatCount = MAXFLOAT;
[self.imageView.layer addAnimation:anim forKey:nil];
CATransition
- fade
交叉淡化过渡
不支持过渡方向
对应的常量为kCATransitionFade
- push
新视图把旧视图推出去
对应的常量为kCATransitionPush
- moveIn
新视图移到旧视图上面
对应的常量为kCATransitionMoveIn
- reveal
将旧视图移开显示下边的新视图
对应的常量为kCATransitionReveal
- cube
立方体反转效果
- oglFlip
上下左右反转效果
- suckEffect
收缩效果,如一块布被抽走
不支持过渡方向
- rippleEffect
滴水效果
不支持过渡方向
- pageCurl
向上翻页效果
- pageUnCurl
向下翻页效果
- cameraIrisHollowOpen
相机镜头打开效果
不支持过渡方向
- cameraIrisHollowClose
相机镜头关闭效果
不支持过渡方向
//转场代码跟转场动画必须连在一起
CATransition *anim = [CATransition animation];
anim.type = @"push";
self.i++;
NSString *image = [NSString stringWithFormat:@"%d",self.i];
self.imageV.image = [UIImage imageNamed:image];
[self.imageV.layer addAnimation:anim forKey:nil];
CAAnimationGroup
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"position.y";
anim.toValue = @400;
CABasicAnimation *anim2 = [CABasicAnimation animation];
anim2.keyPath = @"transform.scale";
anim2.toValue = @0.5;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[anim,anim2];
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
[self.imageV.layer addAnimation:group forKey:nil];
UIView动画跟核心动画的区别
- 核心动画只作用在layer上
- 核心动画看到的只是假象,并没有改变View的真实位置
什么时候选择核心动画
- View不需要跟用户交互
- 要给动画设置变化的路径
- 实现转场动画(核心动画的转场类型更多)
demo https://github.com/KK177/Animation
网友评论