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?
In your info.plist, you need to set the key for
UISupportedInterfaceOrientations
, As seen below.: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: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 eitherYES
orNO
.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:
...to support only landscape orientations:
...to support only landscape-left (as you want):
In addition to what you did, Instead of your
shouldAutorotateToInterfaceOrientation
function, use the following