【问题标题】:cannot force app to portrait-only in iOS9无法在 iOS9 中强制应用仅纵向显示
【发布时间】:2016-01-04 12:23:36
【问题描述】:

我需要我的应用只支持纵向。但是升级到iOS9之后,方向设置好像没有效果了。我已经通过this 回答,这是我的应用设置:

但应用程序仍会进入横向模式。我做错了什么?

【问题讨论】:

  • 你必须取消选中“需要全屏”复选框
  • 已经试过了。不工作。
  • 请检查 info.plist 文件中的“支持的界面方向”,有时 info.plist 不会作为常规选项卡更新。
  • info.plist 包含所有必需的项目。
  • 它必须只显示纵向模式。

标签: ios uiinterfaceorientation


【解决方案1】:

请查看 Info.plist 中的“支持的界面方向”。 它必须显示符合您要求的肖像。有时它不会作为“常规”选项卡中的项目设置进行更新。如果您在此处发现横向,请将其删除。

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>

【讨论】:

    【解决方案2】:

    iOS9 中存在某种错误。它完全忽略了 plist 文件方向设置。所以我不得不将这段代码添加到我的每个 UIViewControllers 以获得纵向。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        if (interfaceOrientation == UIInterfaceOrientationPortrait)
        {
            return YES;
        }
        else
        {
            return NO;
        }
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    
    #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
    - (NSUInteger)supportedInterfaceOrientations
    #else
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations
    #endif
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    【讨论】:

      【解决方案3】:

      看来我找到了问题所在。当我查看 info.plist 的 source 时,我发现了以下内容:

      <key>UISupportedInterfaceOrientations</key>
      <array>
          <string>UIInterfaceOrientationPortrait</string>
      </array>
      <key>UISupportedInterfaceOrientations~ipad</key>
      <array>
          <string>UIInterfaceOrientationPortrait</string>
          <string>UIInterfaceOrientationPortraitUpsideDown</string>
          <string>UIInterfaceOrientationLandscapeLeft</string>
          <string>UIInterfaceOrientationLandscapeRight</string>
      </array>
      

      不知道UISupportedInterfaceOrientations~ipad 密钥是如何产生的。最初以属性列表查看时不显示,但在作为源打开并保存后开始显示在属性列表中。

      现在似乎还有一种方法可以在 general 选项卡中进行设置。感谢SamBtechnerd 让我走上了正确的道路。

      PS:我不确定这是错误还是预期的行为,因此我欢迎对此提出任何见解。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-07
        • 1970-01-01
        • 2011-06-05
        • 2014-10-25
        • 1970-01-01
        相关资源
        最近更新 更多