贡献作者 -【XJDomain】
博客XJ: https://my.oschina.net/shengbingli/blog
GitHub: https://github.com/lishengbing/XJQRCodeToolDemo
使用说明:
调用:
starAnim()
移除:
stopAnim()
/ * 'key' may be any string such that only one animation per unique key
* is added per layer. The special key 'transition' is automatically
* used for transition animations. The nil pointer is also a valid key.
*
*/
/** Animation methods. **/
open func add(_ anim: CAAnimation, forKey key: String?)
上面那个添加方法的注意⚠️:
参数key的作用:如果后面参数key传入:"rotation",可以保证添加动画的唯一性和只会添加一次,特别是在cell中添加这样的话,会保证cell不会复用
fileprivate func starAnim() {
// 1:创建动画对象
let anim = CAKeyframeAnimation(keyPath: "transform.rotation")
anim.values = [(-3 / 180 * M_PI), (3 / 180 * M_PI),(-3 / 180 * M_PI)]
anim.repeatCount = Float(MAX_CANON)
anim.duration = 1
anim.autoreverses = true
iconView.layer.add(anim, forKey: nil)
}
fileprivate func stopAnim() {
iconView.layer.removeAllAnimations()
}