Search code examples
iphonecocoa-touchiosmpmovieplayercontroller

Cocoa-Touch: How to allow MPMoviePlayerController but no other views to autorotate?


I have this iOS 3.2 app (iPad) which has lots of content, and a few videos.

All the views are in portrait, except for the videos which are portrait inline, with a fullscreen option, and I'd like to let the user autorotate the video while fullscreen.

In shouldAutorotateForInterfaceOrientation: my app generally refuses autorotation.

How can I let MPMoviePlayerController's view autorotate, but not any other views in my app?

A few ideas I've thought of:

  1. in shouldAutorotateForInterfaceOrientation::
    return isFullscreenMovieActive;
    which would make the app allow rotation while a movie is in fullscreen mode. This works perfectly except for one huge issue, I cannot force the app back into portrait mode once the user exits fullscreen mode. (i.e. user starts app, finds a movie player, plays it, goes to fullscreen mode, rotates the device, presses done, now he has the app in landscape mode)
    Is there an acceptable way to force rotating to a UIInterfaceOrientation?

  2. Apple actually recommends grabbing MPMoviePlayerController's view from it's view method. When the device rotates, what actually happens is that the app's UIWindow gets a CGAffineTransform applied to it. So I could do this to MPMoviePlayerController's view, but when entering fullscreen mode the view changes and is not the one in the view property.
    So is there any acceptable way to get MPMoviePlayerController's fullscreen view?

Or is there a better solution for this task?


Solution

  • Each view controller can return the orientations it supports with shouldAutorotateForInterfaceOrientation:. Your app's controllers should only return true for the portrait rotations, except for the MPMoviePlayerController. When your app displays the video, present the MPMoviePlayerController over your other view controller with presentModalViewController:animated: (or presentViewController:animated:completion: in iOS 5). Once the video is done, dismiss the special movie player controller, and your other controller should still be in portrait mode.