xcode 删除 iPhone SDK 中应用的纵向功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3176577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:30:48  来源:igfitidea点击:

Remove ability for portrait orientation for app in iPhone SDK

iphonexcodeipadorientation

提问by Don Wilson

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.

有没有办法只允许我的应用在横向模式下可见?我设法将应用程序的方向默认为横向,但是在 iPad 模拟器中,当我执行 Command->Arrow 时,应用程序会旋转为纵向。我已经删除了 plist 中两个 Portrait 条目的“支持的界面方向”下的列表,但这似乎没有改变任何东西。

Any idea?

任何的想法?

回答by Joost Schuur

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

回答by Eiko

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

为“自动旋转”做一个项目查找,并相应地编辑您将找到的方法。

回答by Sahil Belgaonkar

Actually it is

其实是

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

回答by TomG103

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 :)

那只会允许景观。随心所欲地转动手机,它只会停留在左侧或右侧的风景中。玩得开心 :)