Orientation Changes
The iPhone is retrofitted with hardware to sense its state in the surrounding environment. One sensor in particular, the accelerometer, is able to determine the orientation that the iPhone is being held at. How to read the orientation and what to do with it when it's changed are important for applications that need to provide landscape mode support.
Reading the Orientation
The orientation of the iPhone can be read using a static method named deviceOrientation, found in the UIHardware class:
int orientation = [ UIHardware deviceOrientation: YES ];
This method returns one of six different possible orientations identifying how the iPhone is presently being held.
Orientation | Description |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The sensor can be read when the application first starts up, but what's more useful is to know when the orientation has been changed. A change in the orientation is reported automatically to the UIApplication class, the class your GUI application is derived from. A method named deviceOrientationChanged can be overridden ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access