多个UIButton的旋转动画,animationDidStop怎么知道哪个停止了?

时间:2014-11-14 10:32:46

标签: ios animation swift uiview uibutton

我试图让四个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的参数,但我无法将它与任何东西进行比较。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

使用CATransition重写您的方法并使用此问题的解决方案: How to identify CAAnimation within the animationDidStop delegate?