PresentModalViewController detecting animation completion

I noticed that iOS 5 introduced additional options and ways to detect when a view controller's view animation is complete.

Is there a way to do this in earlier versions like iOS 4.x?

I used presentModalViewController

to view a controller and I noticed that you cannot call the exit method if the animation has not finished.

So how can I tell when the animation is complete so I can let it go?


source to share

3 answers

I just tried to fire the fashionably presented VC, on viewDidLoad, viewWillAppear and viewDidAppear. No dice in the first two, but firing works in viewDidAppear. (The view makes sense what it would trigger after the animation).

And you probably know this already, but in case you don't: you don't need to reject the modally submitted VC submitted from the VC that submitted it. Your "wait for the network" VC can check the connection status in viewDidAppear and fire itself if the connection is complete.



There's no exact way to do this - the best you can hopefully do is use viewDidDisappear:

from within a view controller. Be sure to use the boolean instance variable to determine if you fade out due to the presence of the modal view controller or for some other reason.

Honestly, if you are building new software, I strongly recommend that you set up iOS 5 and up. The vast majority of people are modernized, and the rest are in a few months; there is simply no reason to support iOS 4 for new projects.



Is it just a thing that says "wait while I make a network request"? Perhaps you could use a view for this (full size attached to keyWindow) rather than the whole view controller. The Vc that triggers the network request can render the view and remove it with any animation you like. I have a class that does this. Let me know if you want to try and I'll paste it.



All Articles