【问题标题】:Remove ability for portrait orientation for app in iPhone SDK删除 iPhone SDK 中应用的纵向功能
【发布时间】:2011-03-11 17:35:51
【问题描述】:

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

有什么想法吗?

【问题讨论】:

  • “旋转到纵向”是什么意思?您意识到您无法阻止用户物理旋转设备,对吧?
  • 可以,但某些应用程序能够将其方向锁定为横向,即使设备是纵向的。

标签: iphone xcode ipad orientation


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    【解决方案3】:

    在您的视图控制器中,有一个委托方法:

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

    【讨论】:

    • 完美。我知道我以前看过这行代码,只是忘记了。
    • 这个已经过时了;从 iOS 6 开始,此方法已被弃用。
    【解决方案4】:

    其实是

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

    【讨论】:

      【解决方案5】:

      随着一些更新,情况发生了变化。目前,您只需添加以下方法:

      -(NSUInteger)supportedInterfaceOrientations
      {
          return UIInterfaceOrientationMaskLandscape;
      }
      

      这将只允许横向。随心所欲地转动手机,它只会停留在左侧或右侧。玩得开心:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-14
        • 1970-01-01
        • 2015-06-14
        • 1970-01-01
        • 2011-02-07
        • 1970-01-01
        • 2023-03-03
        相关资源
        最近更新 更多