Upgrading an old app (and I mean *old* – code is checking for to see if we have the new iOS 3!) and ran into some frustration with rotation that the blog posts I read weren’t answering.
This app is limited (client budget prevented much that I’d like to have done) and the whole app is portrait and inside a navigation controller exceptfor the streaming video
MPMoviePlayerViewController which should be able to rotate to landscape and which is presented full screen modally via
presentMoviePlayerViewControllerAnimated:. This worked fine until iOS 6 when the
MPMoviePlayerViewController stopped auto rotating.
After much pain it turns out that there are only four things that needed to be done:
- Make sure the
info.plistfor the app has portrait and landscape orientations allowed (you can do this in Xcode visually via the project or target editor’s Summary tab).
- Have your App Delegate implement application:
UIInterfaceOrientationMaskAllButUpsideDown(Yes, I know you don’t really want this for anything except the movie view! Be calm. All will be well :)).
- Have the root view (a navigation controller in this case) implement
NO(this keeps it and all it’s children from rotating which is what we want in this case).
- you’d be good at this point if you had one last key piece… which I didn’t. The window
rootViewControllermust be set or all of this (and a bunch of other things I tried like subclassing
MPMoviePlayerViewControlleretc etc) will not work. Once I set this in my app delegate where it sets up the window everything worked as it should. <whew!>
If your root controller (a navigation controller in this case, but might be a tab view controller) isn’t already a subclass where you can implement
shouldAutorotate then I guess you will have to subclass it to return
Note: If you are supporting iOS 5 you will need to put the appropriate
shouldAutorotateToInterfaceOrientation implementations in your views and return
interfaceOrientation == UIInterfaceOrientationPortrait as usual to keep them from rotating (you may have already had this, but if you set the info.plist to have no rotation then you might not have).