无法仅在xcode 4中将屏幕方向锁定为纵向?

Oma*_*mar 3 iphone xcode cocoa-touch xcode4

在xcode 4中,即使我只选择了肖像,我也无法将屏幕方向锁定为仅纵向.如何以编程方式执行此操作?

   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)

此代码适用于新的空白项目

Jam*_*rpe 10

接受的答案对我来说也不起作用.这样做:

在位于"支持文件"组中的应用程序的属性文件(YOURAPPNAME-Info.plist)中,有一个名为"支持的接口方向"的数组.从阵列中删除两个横向值,您的应用将以纵向方向锁定.


Pen*_*One 6

对于每个视图控制器(或只是父控件),实现-shouldAutorotateToInterfaceOrientation:将默认方向设置为纵向,然后执行:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return NO;
}
Run Code Online (Sandbox Code Playgroud)

或者,您可以这样做:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return interfaceOrientation == UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)

这将允许旋转到纵向但不远离它.