我想知道我怎样才能让这件事永远持续下去。现在持续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)
}

}

最佳答案

您可以添加:
rotateAnimation.repeatCount = Float(CGFloat.max)
或反转并重复:
虽然这可能不是你需要的。
这给了我一个永远旋转的盒子。

    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)

10-06 10:31