I have UITabBarController
app which plays video and shows other information in other UITabBar
tabs. In iOS 6 UIView
rotation methods have been deprecated, and now I need to use shouldAutoRotate
and supportedInterfaceOrientations
methods. For video playing I use MPMoviePlayerViewController
.
How to rotate only this player view? I can only rotate whole app, but don't want to do this. I present MPMoviePlayerViewController
but it doesn't rotate as in iOS 5 and earlier.
In plist
setting I've set only 1 Portrait interface orientation. If I set other - whole app will be rotated.
From Apple's iOS 6 SDK Release Notes:
If you want your whole app to rotate then you should set your Info.plist to support all orientations. Now if you want a specific view to be portrait only you will have to do some sort of subclass and override the autorotation methods to return portrait only. I have an example here:
https://stackoverflow.com/a/12522119/1575017
Unfortunately you'll need to turn on all orientations in your plist and use supportedInterfaceOrientations on all the view controllers you don't want to rotate. (In your case everything but the video player.)
I found the easiest way to set this up is to use the "supported interface orientations" buttons which you can see if you look at Targets....Summary Tab (under iPhone/iPad Deployment info).
Its basically a GUI to set the plist file
Try this,
If TabBarController is RootViewController for window, Then Create Custom Class which inherits TabBarController say CustomTabBarController.h
Add Below method in CustomTabBarController.h
Finally Call Below in AppDelegate.m
You can also subclass UITabBarController to make it ask its children about the shouldAutorotate and supportedInterfaceOrientation like this:
Then you just use your custom container in place of the standard one and it works! just tested.
Ough! A half of a day spent, and the problem solved! He he.
As the documentation above says, this is really it! The core points are:
So, any time something with root controller changes, the system asks app delegate "So, what are we? Rotating or not?"
If "rotating":
then system asks our app delegate for
That's really pretty simple.
How to determine when should we allow Portrait or Landscape etc - is up to you. Testing for root controller didn't work for me because of some points, but this works:
The property "fullScreenVideoIsPlaying" is set up by me manually whenever I need that.
The only other important thing to be careful is the enum. As it says in docs ... (read carefully above iPad/iPhone thing). So, you can play with those as you need.
Another tiny thing was some buggy behaviour after closing the player controller. There was one time when it did not change the orientation, but that happened once and in some strange way, and only in simulator (iOS 6 only, of course). So I even could not react, as it happened unexpectedly and after clicking fast on some other elements of my app, it rotated to normal orientation. So, not sure - might be some delay in simulator work or something (or, really a bug :) ).
Good luck!