Autorotation

Many applications rotate and resize all of their views when the user rotates the device. You could implement this using UIDevice notifications, but it would be a lot of work. Fortunately, you can use autorotation to simplify the process.

If the view on screen is controlled by a view controller, when the device is rotated, the view controller is asked if it is okay to rotate the view. If the view controller agrees, the view is resized and rotated. Its subviews are also resized and rotated.

You will need a UIViewController subclass to get this autorotating behavior. This view controller’s view will have subviews, so we will use the UIViewController template with a XIB file to create this class.

Select FileNewNew File.... From ...

Get iOS Programming: The Big Nerd Ranch Guide 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.