How to restrict my app to landscape mode?

安稳与你 提交于 2019-11-28 17:39:05
Jonathan.

I asked a question with a bounty of 500 that seems to be the same thing you're facing.

From my limited experience it is much easier to make a landscape-only iPhone app than a landscape-only iPad app. I'm not sure why there is any difference, but the steps Apple says to take to make it landscape-only do not work on their own.

Sid

Try this (it works):

-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    }
    else 
    {
        return NO;
    }
}
westsider

Check out this iPhone app in landscape mode, if you haven't already. I was going to suggest simply adding UISupportedInterfaceOrientations to your Info.plist and specifying the two landscape orientations. But, apparently, this is not sufficient, according to answers to cited question.

I believe this is a BUG, I faced this problem also. It is something to do with

UIInterfaceOrientationLandscapeLeft

To replicate this situation:

1) Create a new iPad project using UISplitViewController template

2) Edit info.plist

Supported interface orientations
-Landscape (left home button)
-Landscape (right home button)

3) DetailViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//    return YES;
 NSLog(@"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
 return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}

4) Run it....You will see a blank black view. and no matter how you turn. "UIInterfaceOrientationLandscapeLeft" never detected.

By the way, nacho4d's adding BOOL check work-around is working. Thumbs UP :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!