【问题标题】:how to lock/unlock orientation lock of iphone programmatically?如何以编程方式锁定/解锁 iphone 的方向锁定?
【发布时间】:2011-11-09 21:31:52
【问题描述】:

我们知道锁定/解锁 iPhone 3G 方向的这些简单步骤:

From any screen, double-tap the home button
Scroll as far left as you can on the multitasking dock
The first symbol to the left will be a circular arrow
Select this to either lock or unlock the orientation of your iPhone 3G

但是我们如何以编程方式做到这一点?

【问题讨论】:

    标签: iphone ios4


    【解决方案1】:

    您是在问是否可以为您的应用执行此操作或锁定设备本身的方向?在我看来,您要的是后者,我不得不问您为什么要这样做。无法锁定设备的方向,因为这样对于其他应用程序也会被锁定为纵向模式。

    但是,您只能支持您自己想要的方向。很多应用只支持竖屏模式,游戏一般只支持横屏。

    您可以在 XCode 中设置应用支持的设备方向。在视图控制器上。

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

    假设您想同时支持两个横向。

    【讨论】:

      【解决方案2】:

      您不能以编程方式执行此操作 - 应用更改影响其他所有内容的设置是完全错误的。

      在您自己的应用程序中,您可以通过在您的info.plist 中设置UISupportedInterfaceOrientations 来限制支持的方向(参见文档here)。您还可以通过shouldAutorotateToInterfaceOrientation 限制每个视图的方向(参见文档here

      【讨论】:

        猜你喜欢
        • 2011-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-13
        相关资源
        最近更新 更多