我正在想办法如何让这一切永远持续下去。现在持续 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)
或者反转并重复:
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)
关于xcode - 如何让物体无限旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29527355/