2
votes

How can I cancel and animation started with transitionFromView:toView:duration:options:completion? Actually what I want, is to avoid calling the completation block if animation was cancelled, just because thatblock transitates a state machine.

I guess is possible to cancel the animation because here: https://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html I read this: completion A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called.

Therfore, how can I cancel the animation? Thanks a lot.

1

1 Answers

2
votes

It is the layer of the fromView's superview that animates in this scenario. You can cancel the animation at any time with

[parentView.layer removeAllAnimations];

Your completion callback will still be called, but keep in mind that, as you've quoted above, the callback takes a BOOL argument indicating whether the animation completed or not. Just check the argument and do nothing if it's NO.

Visually, it will look like the animation just jumps to the end. You'll see the toView as the active interface. In fact, the toView was already present within the superview, even from the beginning of the animation; it was just covered up by the layer's presentationLayer during the animation.