Device Orientation

Automatic Adjustment

When a user rotates their device, you may want to rotate the interface to go along with it.

You support different interface orientations by implementing theĀ shouldAutorotateToInterfaceOrientation: method.

If you support an orientation, the frame of all subviews will be adjusted. This adjustment is based on their struts and springs, which are set in the Storyboard.

Struts Springs
Sticks the view to the sides that they are fixed to. Set which dimensions the view scales to as its superview’s bounds change.

By default, the view is not redrawn when its bounds change (i.e. drawRect: is not called automatically). The contentMode property is used to set the redraw behaviour.

Content Mode Portrait Landscape

Note that this is not the same as springs and struts. Content modes move the bits of the drawing around, and do so after springs and struts have been applied. To call drawRect: every time the bounds change, set the content mode to UIViewContentModeRedraw.

Manual Adjustment

You may sometime want to layout the subviews manually. You can do so by implementingĀ willAnimateRotationToInterfaceOrientation:duration:. Note that the second parameter to the method is the duration of the rotation, so you can even animate your layout changes and time them to complete at the same time as the view rotation animation.

  1. Paul Hegarty. Lecture 5 Slides. iPad and iPhone Application Development. Stanford, Nov 14 2011.

Comments are closed.