iOS 6 and auto-rotation tip

by

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:

  1. Make sure the info.plist for the app has portrait and landscape orientations allowed (you can do this in Xcode visually via the project or target editor’s Summary tab).
  2. Have your App Delegate implement application: supportedInterfaceOrientationsForWindow: and return UIInterfaceOrientationMaskAll or UIInterfaceOrientationMaskAllButUpsideDown  (Yes, I know you don’t really want this for anything except the movie view! Be calm. All will be well :)).
  3. Have the root view (a navigation controller in this case) implement shouldAutorotate and return NO (this keeps it and all it’s children from rotating which is what we want in this case).
  4. you’d be good at this point if you had one last key piece… which I didn’t.  The window rootViewController must be set or all of this (and a bunch of other things I tried like subclassing MPMoviePlayerViewController etc 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 NO.

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).

good luck.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: