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 ...

Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.