Ios 快速停止360度动画

Ios 快速停止360度动画,ios,Ios,在我的swift 2应用程序中,我有以下扩展名: extension UIView { func rotate360Degrees(duration: CFTimeInterval = 2.5, completionDelegate: AnyObject? = nil) { let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation") rotateAnimation.fromV

在我的swift 2应用程序中,我有以下扩展名:

extension UIView {

    func rotate360Degrees(duration: CFTimeInterval = 2.5, 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)
    }
}
使用此代码,我可以将图像旋转360度。 现在我想在按下按钮后直接停止这个动画

在我的视图中,控制器是我的按钮的动作。如果按下此按钮,将设置以下值:

self.shouldStopRotating = true
我在同一个vc中也有这个代码部分:

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
  if self.shouldStopRotating == false {
     self.LoadingCircle.rotate360Degrees(completionDelegate: self)
  }
}
我按下按钮后图像将停止,但动画完成后(360度后)图像将停止-但这太晚了


按下按钮后,图像必须直接停止在实际位置上旋转。当按下停止动画的按钮时,尝试添加此按钮:

self.LoadingCircle.layer.removeAllAnimations()
let currentLayer = self.LoadingCircle.layer.presentationLayer();
let currentRotation = currentLayer?.valueForKeyPath("transform.rotation.z")?.floatValue;
let rotation = CGAffineTransformMakeRotation(CGFloat(currentRotation!));
self.LoadingCircle.transform = rotation;

在代码中看不到你在哪里停下来。检查这个按钮后我调用的唯一代码部分是:self.shouldStopRotating=true,但我认为这不足以直接停止动画。现在我正在寻找解决方案。
removeAnimationForKey
在我的链接答案中应该是正确的calli我以前尝试过类似的方法。self.LoadingCircle.layer.RemoveAllianimations()但动画不会直接停止Super对您的措辞“停止但不直接”感到困惑,还是应该是“它将完成但不直接停止”?