Don Wilson
Don Wilson

Reputation: 552

Remove ability for portrait orientation for app in iPhone SDK

Is there a way where I can only allow my app viewable in landscape mode? I've managed to default the application's orientation to landscape, however in the iPad simulator, when I do Command->Arrow, the application rotates to portrait. I've removed the listings in the plist under "Supported interface orientations" for both of the Portrait entries, however that doesn't seem to've changed anything.

Any idea?

Upvotes: 4

Views: 15765

Answers (5)

TomG103
TomG103

Reputation: 312

Things have changed with some updates. Currently, you'll simply need to add the following method:

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

that will only allow landscape. Turn the phone all you like and it will only stay in either left or right landscape. Have fun :)

Upvotes: 0

Sahil Belgaonkar
Sahil Belgaonkar

Reputation: 11

Actually it is

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Upvotes: 1

Joost Schuur
Joost Schuur

Reputation: 4482

In your view controller, there's a delegate method for this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
            (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Upvotes: 11

Eiko
Eiko

Reputation: 25632

Do a project find for "autorotate", and edit the methods you'll find accordingly.

Upvotes: 3

Related Questions