How to animate slide down the current UIViewController along with the UINavigationBar before playing video

2.5k views Asked by At

I've seen this effect on numerous apps, including the YouTube, Fandango, the iPod movie player, Netflix app, the list goes on and on... They are displaying navigation controller UI, and you choose to play a movie (from a button on the current view controller), and then the nav bar as well as the view controller both slide down off the screen in unison, then the video player is revealed.

The only way I know how to acheive this effect is if the current view controller (with the play button) was loaded via presentModalViewController, then calling dismissModalViewControllerAnimated:YES will do the trick. However, the above are not doing this, as I can clearly see the current view controller sliding in from the right, which is typical behavior resulting from a call to pushViewController from the navigation controller.

Any ideas?

1

There are 1 answers

3
Dimitry On BEST ANSWER

For starters, you may have to call [self presentModalViewController:moviePlayerViewController animated:YES] on the top-most controller. In your case, that would be the navigation controller. E.g.

// initialize moviePlayerViewController
[self.navigationController
  presentModalViewController:moviePlayerViewController
                    animated:YES];

But this solution only fades the movie controller in, it does not slide the navigation controller's view out of the way. For that, you will have to animate the view in the desired way. I recommend the following solution:

Custom Animation for Pushing a UIViewController

After your animation is completed, you display the movie player controller.