MPMovieViewController doesn't autorotate - iphone

I have an application that plays videos via a MPMoviePlayerViewController that's presented after a selection action performed on a UITableViewController, which is embedded in a UINavigationController which is embedded in a UITabBarController.
TabBar Controller > Navigation Controller > Table View Controller * MPMoviePlayerViewController
Everything works as expected in iOS5, but upgrading to iOS6 I found that the video did not rotate as expected after being presented. If I selected more supported interface orientations on the target summary page, it causes the whole application to rotate.
The Apple documentation says the following in the UIViewController class reference:
In iOS 6, your app supports the interface orientations defined in your
app’s Info.plist file. A view controller can override the
supportedInterfaceOrientations method to limit the list of supported
orientations. Generally, the system calls this method only on the root
view controller of the window or a view controller presented to fill
the entire screen; child view controllers use the portion of the
window provided for them by their parent view controller and no longer
participate in directly in decisions about what rotations are
supported. The intersection of the app’s orientation mask and the view
controller’s orientation mask is used to determine which orientations
a view controller can be rotated into.
But I'm not sure when the child view controllers are actually participating in the rotation decision. Will I need to change the way my Tab Bar Controller responds to shouldAutorotate and supportedInterfaceOrientations when a movie is playing?

The basic answer is that the rotation behavior of all View Controllers is determined by the "top most" view controller, but the MPMoviePlayerViewController determines its own rotation behavior since it acts as a "view controller presented to fill the entire screen".
For example: if I had a single-view application, the auto-rotate methods would be handled on the view controller for the single view. If I embed that view in a tab bar, then the tab bar controller implementation would handle those messages. If I embed the view in a navigation bar inside a tab bar, the tab bar implementation would still be the one handling the messages (it's still the "root view controller" if the other view controllers are embedded inside it).
MPMoviePlayerViewController will respond YES to shouldAutorotate and will support landscape orientations. It is still possible to prevent the movie from rotating (by not having portrait orientations selected on the target summary page), but the settings you choose for your view controller hierarchy will not affect its ability to do so. When the MPMoviePlayerViewController is presented, it is the view controller handling the autorotate messages. When it is not presented, the Tab Bar Controller is in charge.

Related

View is not rotating

I am making a navigation based app and I need only portrait orientation except in a ZoomPictureViewController ( Zoom in, zoom out images) that supports all orientations.
I am presenting ZoomPictureViewController and returning YES in shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
But I get no rotation. I know that shouldAutorotateToInterfaceOrientation, willRotateToInterfaceOrientation, RotateToInterfaceOrientation are only get called on the current/visible view controller but this is not happening in my case. I have checked it via putting breakpoints and NSLog.
Are you using any type of Navigation Controller or a Tab View Controller? I've noticed that there are issues when rotating a UIView that's not the first or only view as a direct child of the main window.
So if your UIView is part of a Navigation Controller or a Tab View Controller, you'll also need to override shouldAutoRotateToInterfaceOrientation on the Navigation Controller or Tab View Controller.
Also I here's an important gotcha in the Apple documentation that might explain the problem you are having.
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view
controllers support such an
orientation. When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.

UiTabViewControllers+UINavigationControllers+UIViewControllers Orientation

I have a UITabViewController application with 4 tabs and each tab with a UINavigationController, each with a UItableView. When a row is clicked it navigates to another view.
I would like to support Landscape Orientation only for a certain UIViewController and not in any other view.
When I set "return YES" on each UINavigationcontrollers (BOOL)shouldAutorotateToInterfaceOrientation: method the app orients in all the views even in the uitableview.
How do I get this right? I am very confused
If you want to maintain the views as per your requirement then you have to make different view for each tab also in Interface builder you have to create landscape view wherever you required. When you add that landscape view, which is created in interface builder will be shown as landscape only. There will be no need of shouldAutorotateInterfaceOrientation method.

Problems with Interface Orientation and UITabBarController

Quick problem:
I have an UITabBarController with 2 navigation controllers [lets call them Left and Right Controller]
On the default selected Left Controller I can push a new View Controller that detects interface orientation.
On the Right Controller I can push the same View Controller but it won't detect interface orientation, or for that matter, It won't even go into the shouldAutoRotateInterface method at all T___T
Haaalp!!
If it is of any relevance, the View Contoller that I'm pushing use the hidesBottomBarWhenPushed property.
Most likely this is your problem:
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view controllers support such an orientation.
When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.
The solution is to override the following method on every view controller leading to your view:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return YES;
}
For example, instead using the default UITabBarController in IB, replace it with your own subclass containing just the method above.
I'm a bit late to the party on this, but I ran into a problem with autorotation at startup for a tab bar app I wanted always to run in portrait.
The app's plist has the necessary settings to both start in and only allow portrait mode, and all my view controllers only allow portrait mode. Yet, when I started the app holding my iPhone in landscape, the app started in portrait, but then rotated to landscape!
Rather than subclass UITabBarController, I simply overrode UITabBarController's shouldAutorotateToInterfaceOrientation: method using a category on class UITabBarController. I included this code in my app delegate:
#implementation UITabBarController(UITabBarControllerCategory)
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Works beautifully, and is quite lightweight.
does your uitabbarcontroller implement the auto rotate? any child viewcontroller that wants to implement autorotate has to have its parent implement autorotate.

How to make a UISplitViewController in portrait mode?

I want to make a UISplitViewController in portrait mode just like in the Settings app. How can I do it?
A bit late, but also take a look at the MGSplitViewController by Matt Gemmel. It does what you need and so much more. It's what UISplitViewController should be, and it's a snap to implement.
From the UISplitViewController class documentation:
A split view controller supports the
same interface orientations as its
currently visible child view
controllers. Both view controllers are
displayed in landscape orientations
but only the detail view controller is
displayed in portrait orientations.
When transitioning between
orientations, the split view
controller sends messages to its
delegate object to coordinate the
display of a popover with the hidden
view controller. For more information
on the methods of this delegate
object, see
UISplitViewControllerDelegate Protocol
Reference.
(Emphesis added.)

iPhone Dev - Autorotating all views

(By the way I develop without Interface Builder)
If you have a tab bar app that autorotates, so all the autoresizing masks are set, how do you make it work with all the views? Like if one view autorotates to landscape, you select a different tab in the tab bar, and the view associated with that tab comes up, and its all messed because it never got autorotated, it got initialized with the frame that makes it fit in portrait mode, even though the autoresizingmasks are set to have it look fine in landscape, it never got rotated. Whats the solution? (By the way, I'm lazy loading the views, so the only view loaded at any given time is the view(view controller's view) associated with the selected tab).
Does declaring all the required orientations in the didrotatefrominterfaceorientation method in every view controller you are using fix the problem?
e.g. your main view, with the tab bar is called "mainView", and when you choose a tab, it loads a view called "firstView", does the "firstView" view controller have the orientations set?
If a view controller is not loaded, it won't be able to respond to autorotation messages. So in your view controller, when it's loaded from the nib, it should check the orientation and resize and move things as necessary.