通过给继承与 UIImageView 的类 CXGImageView 添加 CABasicAnimation 转动动画,实现播放器图片转动效果.
主要提供三个方法: startRotating, stopRotating,resumeRotate
- startRotating
/// 开始动画
func startRotating() {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.isRemovedOnCompletion = false // 避免点击 Home 键返回,动画停止
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = Double.pi * 2
rotateAnimation