O'Reilly logo

iPad Application Development For Dummies, 3rd Edition by Neal Goldstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding Autorotation

In Chapter 5 I said I would explain more about view rotation when the orientation changes.

One of the responsibilities of the UIViewController class is to work with the application’s window to handle device rotation (also known as device orientation changes). Although the UIViewController class itself already includes the functionality to animate the transition from the current orientation to the new one (which you can override if you need to lay out the view again for the new orientation), it must also communicate to the application window whether it in fact wants to support a particular orientation.

This communication is accomplished through the UIViewController method shouldAutorotateToInterfaceOrientation:. The should AutorotateToInterfaceOrientation: message, with the new orientation as a parameter, is sent to the view controller when the user rotates the device. If the view controller supports that orientation, it returns YES; if it doesn’t, it returns NO.

When you use the Master-Detail Application template to create your project, that template generates an RTDetailViewController that supports all orientations on the iPad and almost all orientations on the iPhone (The exception for the iPhone is upside down.). Listing 8-5 shows what the template comes up with.

Listing 8-5: The Master-Detail Application Template’s shouldAutorotateToInterfaceOrientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:

(UIInterfaceOrientation)interfaceOrientation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required