Skip to Content
Beginning iOS 5 Application Development
book

Beginning iOS 5 Application Development

by Wei-Meng Lee
January 2012
Beginner content levelBeginner
655 pages
16h 35m
English
Wrox
Content preview from Beginning iOS 5 Application Development

PROGRAMMATICALLY ROTATING THE SCREEN

You've seen how your application can handle changes in device orientation when the user rotates the device. Sometimes (such as when you are developing a game), however, you want to force the application to display in a certain orientation independently of the device's orientation.

There are two scenarios to consider:

  • Rotating the screen orientation during runtime when your application is running
  • Displaying the screen in a fixed orientation when the View window has been loaded

Rotating during Runtime

During runtime, you can programmatically rotate the screen by using the setOrientation: method on an instance of the UIDevice class. Suppose you want to let users change the screen orientation: They press the Round Rect Button. Using the project created earlier, you can code it as follows (you need to connect the Touch Up Inside event of the button to this IBAction):

-(IBAction) btnClicked: (id) sender{
    [[UIDevice currentDevice]
        setOrientation:UIInterfaceOrientationLandscapeLeft];
}

The setOrientation: method takes a single parameter specifying the orientation to which you want to change.

image NOTE After you have programmatically switched the orientation of your application, your application's rotation can still be changed when the device is physically rotated. The orientation that it can be changed to is dependent on what you set in the shouldAutorotateToInterfaceOrientation: ...

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.
Start your free trial

You might also like

Mastering iOS 12 Programming - Third Edition

Mastering iOS 12 Programming - Third Edition

Donny Wals
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9781118144251Purchase book