取消 UIView 动画 - self.view.layer 删除所有动画不起作用



我有一个UIView动画正在进行,我需要在我的iOS应用程序中取消。 我试过这个:

[self.view.layer removeAllAnimations];

但它没有用。 动画继续。 这是我的动画代码:

[UIView animateWithDuration:1.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
recognizer.view.transform = CGAffineTransformTranslate(recognizer.view.transform, translation.x, translation.y);
} completion:^(BOOL finished) {
            NSLog(@"completed animation, now do whatever");
        }];

有人对为什么它不起作用有任何想法吗?

您要将该动画添加到识别器的视图中,因此必须将其从同一视图的图层中删除。

所以而不是

[self.view.layer removeAllAnimations];

你可能想要

[recognizer.view.layer removeAllAnimations];

要保持转换的当前状态,请从表示层获取该转换。表示层是实际反映动画期间更改的层。

recognizer.view.layer.transform = recognizer.view.layer.presentationLayer.transform;

好的 - 刚刚想通了。 将动画组件 beng 从图像视图顶部的手势识别器更改为图像视图本身。 现在,就在停止动画的代码之前,我有:

 truckView.frame = [[trackView.layer presentationLayer] frame];
 [truckView.layer removeAllAnimations];

所以这是这样做的方法。 感谢您的帮助,使我得出了这个答案,

山 姆

最新更新