核心动画
特点 1. 自己去 自己可以回来
2. 动画移动的图层, 真实的位置 没有改变
CALayer
基本属性
backergroundColor 背景颜色 [UIColor redColor].CGColor
anchorPoint 锚点CGPoint
值得范围是0到1之间
position 位置 CGPoint
bounds 大小 CGRect
opacity 透明度
contents 内容id类型
其他属性
边框
borderWidth 边框宽度
borderColor 边框颜色
阴影
shadowColor 阴影颜色
shadowOffset 阴影位置
shadowRadius 阴影半径
==需要设置阴影的透明度==
shadowOpacity 阴影透明度
圆角
cornerRadius 设置圆角
masksToBounds 周围的遮罩 ==如果去掉遮罩那么阴影效果就不会显示==
隐式动画
自带隐式动画,不过可以手动关闭
[CATransaction begin]; 开启事务
[CATransaction setDisableActions:YES]; 关闭动画
[CATransaction commit]; 提交事物
Transform属性
self.layer.transform = CATransform3DTranslate(self.layer.transform, 30, 0, 0); 平移
self.layer.transform = CATransform3DScale(self.layer.transform, 0.5, 0.5, 0); 缩放
self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI_4, 1, 1, 1); 旋转
基本动画(CABasicAnimation)
因为是NSOBjiet的分类所以不需要设置代理
repeatCount 循环次数
duration 单次运行完毕所需时间
Position(X轴 Y轴)
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"position.y"],
key:表示你想让它产生那个属性的动画, position界面的移动使用
basic.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 500)]; 移动的位置
basic.removedOnCompletion = NO; 到了那个移动位置后,是否返回
basic.fillMode = kCAFillModeForwards; 动画的阶段模式,在动画还没开始前 和上面的一起搭配使用,固定用法
Transform(Rotation And Scale)
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 旋转
basic.toValue = @(M_PI * 2.5); 设置属性 即旋转的角度
[self.layer addAnimation:basic forKey:nil]; 需要添加到layer上面
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 缩放
basic.toValue = @(0.5); 设置属性
basic.repeatCount = MAXFLOAT;
basic.duration = 2.0;
[self.layer addAnimation:basic forKey:nil]; 添加
关键帧动画(CAKeyframeAnimation)
Values 属性可以包含多个动作
Path 属性可以设置他的移动路径
沿着固定的点进行移动
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//设置属性
NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(30, 30)];
NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(30, 500)];
NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(360, 500)];
NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(360, 30)];
key.values = @[value1,value2,value3,value4,value1];
key.repeatCount = MAXFLOAT;
key.duration = 3.0;
//2.添加
[self.layer addAnimation:key forKey:nil];
沿绘制路径移动
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 400, 100, 300)];
key.path = path.CGPath;
key.duration = 2.0;
//2.添加
[self.layer addAnimation:key forKey:nil];
平面的抖动 (通过旋转实现)
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
key.values = @[@(-M_PI_4 * 0.03),@(M_PI_4 * 0.03),@(M_PI_4 * 0.03)];
key.repeatCount = 30;
//2.添加
[self.layer addAnimation:key forKey:nil];
转场动画(CATransition)
CATransition *sition = [CATransition animation];
//设置属性
//样式
sition.type = kCATransitionMoveIn;
//方向
sition.subtype = kCATransitionFromBottom;
[self.myImageView.layer addAnimation:sition forKey:nil];
组动画(CAAnimationGroup)
//1.创建动画对象
CAAnimationGroup *group = [CAAnimationGroup animation];
//1.创建动画
CAKeyframeAnimation *key = [CAKeyframeAnimation animationWithKeyPath:@"position"];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(30, 300, 300, 200)];
key.path = path.CGPath;
//1.创建动画对象
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//设置属性
basic.toValue = @(0.1);
//1.旋转
//1.创建动画 基本动画 transform.rotation 默认是绕着Z轴
CABasicAnimation *basic1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//设置属性
basic1.toValue = @(M_PI * 10);
//包含多个动画对象
group.animations = @[key,basic,basic1];
group.duration = 3;
group.repeatCount = 30;
//2.添加动画
[self.layer addAnimation:group forKey:nil];
[TOC]