layer添加动画
@interface CALayer : NSObject
//layer添加动画
- (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key;
在上下文中绘制图层
//NSObject的CALayer代理,NSObject对象可自动调用
@interface NSObject (CALayerDelegate)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
CAAnimation
@interface CAAnimation : NSObject
//代理
@property(nullable, strong) id delegate;
//动画完成是否移除
@property(getter=isRemovedOnCompletion) BOOL removedOnCompletion;
//速度控制函数
@property(nullable, strong) CAMediaTimingFunction *timingFunction;
basic.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//同时设置(1)fillMode = kCAFillModeForwards,(2)removedOnCompletion = NO,可使layer停留在动画结束位置
kCAFillModeForwards;
@interface NSObject (CAAnimationDelegate)
//动画开始调用
- (void)animationDidStart:(CAAnimation *)anim;
//动画结束调用
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@protocol CAMediaTiming
//自动返回初始位置
@property BOOL autoreverses;
//持续时间
@property CFTimeInterval duration;
//开始时间
@property CFTimeInterval beginTime;
//时间偏移
@property CFTimeInterval timeOffset;
//重复时间
@property CFTimeInterval repeatDuration;
//重复次数(若设置重复时间,则无用)
@property float repeatCount;
//速度
@property float speed;
//填充样式
@property(copy) NSString *fillMode;
kCAFillModeForwards;
kCAFillModeBackwards;
kCAFillModeBoth;
kCAFillModeRemoved;
CAPropertyAnimation
@interface CAPropertyAnimation : CAAnimation
//创建带路径的动画
//path:搜索官方文档CALayer Animatable Properties
//对于transform:可具体设置到x,y,z,如"transform.rotation.x"
+ (instancetype)animationWithKeyPath:(nullable NSString *)path;
CABasicAnimation(基本动画)
@interface CABasicAnimation : CAPropertyAnimation
//起点值
@property(nullable, strong) id fromValue;
//终点值
@property(nullable, strong) id toValue;
//过程值
@property(nullable, strong) id byValue;
CAKeyframeAnimation(关键帧动画)
@interface CAKeyframeAnimation : CAPropertyAnimation
//各个动画点数组
@property(nullable, copy) NSArray *values;
封装颜色对象
(__bridge id)([UIColor orangeColor].CGColor)
封装动画对象
+ (NSValue *)valueWithCATransform3D:(CATransform3D)t;
[NSValue valueWithCATransform3D:CATransform3DMakeScale(2, 2, 2)]
CAAnimationGroup(动画组动画)
@interface CAAnimationGroup : CAAnimation
@property(nullable, copy) NSArray<CAAnimation *> *animations;