版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25639809/article/details/85046609
protocol RotationAnimatedProtocol {
func startRotationAnimation()
func stopRotationAnimation()
}
extension UIImageView: RotationAnimatedProtocol {
func startRotationAnimation() {
let rotationAnim = CAKeyframeAnimation(keyPath: "transform.rotation.z")
rotationAnim.keyTimes = [0, 0.5, 0.85, 1]
rotationAnim.values = [0, CGFloat(Double.pi), CGFloat(Double.pi) * 1.7, CGFloat(Double.pi) * 2]
// rotationAnim.fromValue = 0
// rotationAnim.toValue = Double.pi * 2
rotationAnim.repeatCount = MAXFLOAT
rotationAnim.duration = 3
rotationAnim.isRemovedOnCompletion = false
self.layer.add(rotationAnim, forKey: nil)
}
func stopRotationAnimation() {
self.layer.removeAllAnimations()
}
}