我正在尝试让四个 UIButton 在 Swift 中轮换。我得到了这个:
import UIKit
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 1.0, 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)
}
}
但我需要它重复一遍。在我的UIViewController中,我使用了animationDidStop函数,但我怎么知道四个动画中的哪一个触发了它?它有一个名为CAAnimation的参数,但我无法将其与任何东西进行比较。有什么建议吗?
使用 CATransition 重写您的方法,并使用以下问题中的解决方案:如何识别动画中的CAAnimationDidStop委托?