I've got a UIView Animation going on that I need to cancel in my iOS app. I've tried this:
[self.view.layer removeAllAnimations];
But it didn't work. The animation continued. Here is my animation code:
[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");
}];
Does anybody have any ideas as to why it's not working?
You are adding that animation to recognizer's view, hence you will have to remove it from that same view's layer.
So instead of
[self.view.layer removeAllAnimations];
you may want to
[recognizer.view.layer removeAllAnimations];
And to keep the current status of the transformation, fetch that one from the presentation layer. The presentation layer is the one that actually reflects the changes during the animation.
recognizer.view.layer.transform = recognizer.view.layer.presentationLayer.transform;
Ok - just figured it out. Changed the component beng animated from the gesture recogniser on top of the image view to the image view itself. Now, just before the code to stop the animation, I have:
truckView.frame = [[trackView.layer presentationLayer] frame];
[truckView.layer removeAllAnimations];
So this is the way to do it. Thanks for the help that led me to this answer,
Sam
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With