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()
}
}
Swift旋转动画
最新推荐文章于 2023-01-04 08:25:41 发布