Keep iPhone rotation in landscape?

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?

Answers


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

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

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);
}

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:

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

Need Your Help

Test Case Design and responsibility of Testers, Developers, Customers

testcase testcomplete user-acceptance-testing software-lifecycle

So it seems like a lot of people are playing the blame game around where I work, and it brings up an interesting question.

copy_from_user returns error

linux copy kernel

I'm trying to create a store function for a sysfs file that holds the integer "timer_interval" (a global variable).