I'm reading View Controller Programming Guide for iOS these days, it says:
Because transitions can be canceled, you should use the return value of the transitionWasCancelled method of the context object to determine what cleanup is required. When a presentation is canceled, your animator must undo any modifications it made to the view hierarchy. A successful dismissal requires similar actions.
in Presentations and Transitions->Customizing the Transition Animations->Implementing Your Animator Objects->Cleaning Up After the Animations.
And sample code provided by Apple:
BOOL success = ![transitionContext transitionWasCancelled];
// After a failed presentation or successful dismissal, remove the view.
if ((self.presenting && !success) || (!self.presenting && success)) {
[toView removeFromSuperview];
}
// Notify UIKit that the transition has finished
[transitionContext completeTransition:success];
I know that in dismissal, we first need to add toView to container view, but why we need to remove toView after successful dismissal?
I have tested that if I don't call removeFromSuperview
after successful dismissal, everything works fine.
And what will happen if the dismissal failed? It will still show the presented view controller or dismiss it and show the presenting view controller?
Anyone know about this? Thanks a lot.
Usually this will happen when you're using custom animations with interactions. But if in case animation gets cancelled and if you do not handle cancel state then, it will remain in presented view controller state.(in your case)
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