xcode - 如何让物体无限旋转

标签 xcode swift

我正在想办法如何让这一切永远持续下去。现在持续 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/

相关文章:

iphone - 从 super View 中删除多个 View

ios - 新应用和应用更新必须使用公共(public) (GM) 版本构建

ios - 从 Swift 中的 Int 数组中删除前 n 个元素

ios - Firebase 和线程 1

iphone - 在 Xcode 中重命名或重构文件

ios - CCLabelTTF 支持的字体?

xcode - 如何在 Xcode Debugger 中打印 NSString 的地址

SwiftUI 系统光标

SwiftLint Rule for Braces 在下一行,但有一些异常(exception)

ios - 在 Siesta 中覆盖本地数据?