0
votes

I'm making an app that is only in landscape mode but I've found that when I rotate the device, the app auto-rotates to that orientation. I specified in the project summary that I wanted only "Landscape Left" and then in each view controller I put

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
 {
 return UIInterfaceOrientationLandscapeLeft; 
 }

Although the app starts in landscape when I click rotate right or left, the simulator goes into portrait as it should but then the app auto-rotates as well. How can I get the app to stay in landscape even when the device is rotated?

3
Does it do it on a device too? It could be something goofy with the simulator.WhoaItsAFactorial

3 Answers

1
votes

In addition to what you did, Instead of your shouldAutorotateToInterfaceOrientation function, use the following

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
0
votes

I think you have misunderstood what the shouldAutorotateToInterfaceOrientation: is for. It is not asking you "What orientations do you support?", it is asking you "Do you support this interface orientation?". So your answer should be either YES or NO.

It will ask you this each time before it decides to change orientation, so you can change your mind and sometimes support it, sometimes not (if you really want).

For example, to support all orientations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

...to support only landscape orientations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
        (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

...to support only landscape-left (as you want):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return(interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
-1
votes

In your info.plist, you need to set the key for UISupportedInterfaceOrientations, As seen below.:

enter image description here

This limit's my app to run only in Landscape mode, in addition to your shouldAutorotateToInterfaceOrientation: method. If you're supporting Landscape Left/Right. Your method should look like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return  (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}