【问题标题】:Unable to lock screen orientation to portrait only in xcode 4?无法仅在 xcode 4 中将屏幕方向锁定为纵向?
【发布时间】:2011-10-21 05:56:35
【问题描述】:

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

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

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

【问题讨论】:

  • 请发布您目前拥有的代码。

标签: iphone xcode cocoa-touch xcode4


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    或者,您可以这样做:

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

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

    【讨论】:

    • 似乎它坚持我开始项目的设置。我制作了一个新的空白应用程序,它可以工作,但不能在我现有的应用程序中使用!!!真的很烦!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多