有关动画,我们可能用UIView的动画,或是会用到CABasicAnimation比较多一点.
有关CAAnimation的基础知识结构图,我简单画了个图
CABasicAnimation通过设置keyPath来设置类型
duration:动画时长
fromValue/toValue 动画起始位置,根据keypath不同,传值不同.
reaptCount重复次数
设置动画在执行结束后不返回原来位置需设置:
removedOnCompletion = NO position.fillMode = kCAFillModeForwards;
keypath属性
transform.scale = 比例转换
transform.rotation = 旋转
transform.rotation.x = x轴旋转
transform.rotation.y = y轴旋转
opacity = 透明度
margin = 边距
position = 位移
backgroundColor = 背景颜色
cornerRadius = 圆角
borderWidth = 边框宽度
bounds = 位置,体积
contents = 内容
contentsRect = 面积
frame = 位置,体积
hidden = 是否隐藏
shadowColor = 阴影颜色
shadowOffset = 阴影偏移
shadowOpacity = 阴影透明
shadowRadius = 阴影半径
CAAnimationDelegate在CAAnimation中是strong,这对于代理的使用weak,来避免循环引用.
动画是异步的,delegate随时会被释放掉,一般你不会持有一个CAAnimation的强引用.
这是内存管理规则中的一个例外.
CABasicAnimation和CALayer,CAShaperLayer一起.
demo地址:https://github.com/lizhengjin/CAAnimationTest