Kevin McNeish Blog

All things iOS, Kindle and .NET

Recent Posts

Tags

News

  • First books in my new book series, "iOS App Development for Non-Programmers" are now available! iBookStore: http://itunes.apple.com/us/book/book-1-diving-in-ios-app-development/id558788074?mt=11 Amazon: http://www.amazon.com/dp/B0097N8XBE Amazon: http://www.amazon.com/dp/B0099RQGMQ

Community

Email Notifications

Archives

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 

 

Comments

John Mcleod said:

What should be a proper technique to include ios 5 and 6?

# January 3, 2013 9:53 AM
Leave a Comment

(required) 

(required) 

(optional)
 

(required) 

If you can't read this number refresh your screen
Enter the numbers above: