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

时间:2011-08-05 22:15:04

标签: iphone xcode cocoa-touch xcode4

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

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

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

2 个答案:

答案 0 :(得分:10)

接受的答案对我也不起作用。这样做了:

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

答案 1 :(得分:6)

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

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

或者,您可以这样做:

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

允许旋转为纵向但不远离它。

相关问题