Handling Autorotation in IOS 5 and iOS 6 – supportedInterfaceOrientations and shouldAutorotate

In iOS 5, the shouldAutorotateToInterfaceOrientation: method was used to specify which orientations an App supported. This method was deprecated in iOS 6.

When a method is deprecated, it typically means that you should avoid using it because it has been superseded. In this case, shouldAutoRotateToInterfaceOrientation: is never called on a device that is running iOS 6, although it is still called under iOS 5.

So, if you want your App to work on devices running iOS 5 (you usually do), then you should still implement the shouldAutoRotateToInterfaceOrientation: method.

In iOS 6, Apple has replaced this method with two other methods:

  • supportedInterfaceOrientations:
  • shouldAutorotate

If you don’t implement these methods, your App will support the following orientations by default in iOS 6:

  • iPhone – All orientations exception portrait-upside down
  • iPad – All orientations

If you want to limit the orientations supported by your App in iOS 6, you need to implement the new supportedInterfaceOrientations method to indicate the orientations your App supports. This method returns a bit mask specifying which orientations are supported. For example, the following code indicates the App supports portrait, and landscape-left orientations:

– (NSInteger)supportedInterfaceOrientations
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;

In this example, the vertical line indicates the Objective-C bitwise inclusive OR operator.

The shouldAutorotate method is intended to temporarily disable automatic rotation. By default, this method returns YES. You can override this method and return NO to turn off automatic rotation.

When moving your App to iOS 6, you should also check your project’s app delegate class to see if there is code in its application: didFinishLaunchingWithOptions: method like this:

[window addSubview:viewController.view];

If there is, it will prevent autorotation from working properly. You need to change it to:

window.rootViewController = tabBarController;

After making these changes, your App should autorotate properly in iOS6.

For more information, check out Apple’s Supporting Multiple Interface Orientations documentation.

Kevin McNeish
Author of the iOS App Development for Non-Programmers series
Twitter: @kjmcneish


8 thoughts on “Handling Autorotation in IOS 5 and iOS 6 – supportedInterfaceOrientations and shouldAutorotate

  1. Hi, I intended to cratee you the very little remark to help say thanks a lot the moment again for all the incredible suggestions you’ve provided above. It is simply shockingly open-handed with you to make unhampered precisely what many people would’ve advertised as an ebook to make some cash for their own end, certainly since you could possibly have tried it in the event you decided. The guidelines likewise served like a good way to be aware that some people have similar interest really like my very own to learn a lot more on the subject of this matter. Certainly there are a lot more enjoyable periods in the future for many who browse through your blog. thankyou

  2. Almost worked. Xcode did not accept the line:

    window.rootViewController = tabBarController;

    as it did not recognize the identifier tabBarController. However, when I changed it to

    window.rootViewController = viewController;

    it worked just fine. Many thanks!


Leave a Reply to Tom Yunck Cancel reply

Your email address will not be published. Required fields are marked *