Autorotate in iOS 6 has strange behaviour Autorotate in iOS 6 has strange behaviour ios ios

Autorotate in iOS 6 has strange behaviour


From Apple's iOS 6 SDK Release Notes:

Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.

More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.

A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.

The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller. The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.

For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.

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


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:

More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.

So, any time something with root controller changes, the system asks app delegate "So, what are we? Rotating or not?"

If "rotating":

the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method

then system asks our app delegate for

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {        return ...;}

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:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {        return self.fullScreenVideoIsPlaying ?        UIInterfaceOrientationMaskAllButUpsideDown :        UIInterfaceOrientationMaskPortrait;}

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!


I had the same problem with my app.

How the rotation in iOS 6 work is that.

=> when ever you are using UINavigationCOntroller the method in AppDelegate

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window    {   return }

decides whether to rotate or not.

=> when the view is presented in the Modal presentation style the method

- (BOOL)shouldAutorotate

which is inside the viewController for that view triggers the method in the appDelegate. And as 1st case appDelegate decides to rotate or not.

My Solution::

What I did for Modal presentation was that. Created a flag in app delegate.

when ever the flag is YES it rotates to Landscape and else its only Portrait.

- (NSUInteger)application:(UIApplication*)applicationsupportedInterfaceOrientationsForWindow:(UIWindow*)window{    if(self.shouldRotate ) //shouldRotate is my flag    {        self.shouldRotate = NO;        return (UIInterfaceOrientationMaskAll);    }    return (UIInterfaceOrientationMaskPortrait);}

And to toggle between rotations

- (BOOL)shouldAutorotate{    YourAppDelegate *mainDelegate = (YourAppDelegate*)[[UIApplication sharedApplication]delegate];    mainDelegate.shouldRotate = YES;    return YES;}

Note: This works is only for view that are Modely Presented. Using Flag, not a good coding practice.