我试图弄清楚如何才能永远保持这种状态。现在它持续1秒。
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 20, completionDelegate: AnyObject? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = duration
if let delegate: AnyObject = completionDelegate {
rotateAnimation.delegate = delegate
}
self.layer.addAnimation(rotateAnimation, forKey: nil)
}
}
答案 0 :(得分:2)
您可以添加:
rotateAnimation.repeatCount = Float(CGFloat.max)
或反转并重复:
rotateAnimation.autoreverse = true
//虽然这可能不是您所需要的。
这给了我一个永远旋转的盒子。
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = duration
rotateAnimation.autoreverses = true
rotateAnimation.repeatCount = Float(CGFloat.max)