O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

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

RESPONDING TO DEVICE ROTATIONS

One of the features that modern mobile devices support is the capability to detect the current orientation — portrait or landscape — of the device. An application can take advantage of this to re-adjust the device's screen to maximize use of the new orientation. A good example is Safari on the iPhone. When you rotate the device to landscape orientation, Safari automatically rotates its view so that you have a wider screen to view the content of the page (see Figure 7-1).

The iOS SDK contains several events that you can handle to ensure that your application is aware of changes in orientation. Check them out in the following Try It Out.

image

FIGURE 7-1

TRY IT OUT: Supporting Different Screen Orientations

image

  1. Using Xcode, create a new Single View Application (iPhone) project and name it ScreenRotations. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Press Command-R to test the application on the iPhone 4 Simulator.
  3. Change the iPhone Simulator orientation by pressing either Command-→ (rotate it to the right) or Command-← (rotate it to the left) key combination. Observe that the application stays upright when the Simulator is either in portrait (upright) mode or in landscape ...

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