【问题标题】:Xcode not obeying device orientationXcode 不遵守设备方向
【发布时间】:2017-07-05 21:37:08
【问题描述】:

我已将设备方向设置为在 Xcode 中仅检查“纵向”。 但是,当我在模拟器中运行我的应用程序时,它会向所有方向旋转。

My Xcode setting

Showing correctly in Portrait (intended) and Landscape (not intended)

以前有人遇到过同样的问题吗? 谢谢

【问题讨论】:

  • 检查您的info.plist 中的支持的界面方向
  • 我已经在我的info.plist UISupportedInterfaceOrientationsUIInterfaceOrientationPortrait 中包含了以下内容
  • 我遇到了同样的问题。 info.plist 也不错,运气好吗?
  • 同样的问题。有人找到原因了吗?
  • 同样的问题!这是 Xcode 和/或 swiftUI 的错误。我们对 Apple 的期望远不止这些垃圾!!

标签: ios objective-c iphone xcode orientation


【解决方案1】:

Xcode 中的“常规”->“部署信息”UI 可能具有欺骗性。检查info.plist 中的这两个键:

UISupportedInterfaceOrientations

UISupportedInterfaceOrientations~ipad

【讨论】:

  • 我遇到了同样的问题,我的只显示Portrait(bottom home button)
  • 我将UISupportedInterfaceOrientationsUISupportedInterfaceOrientations~ipad 都设置为UIInterfaceOrientationPortrait,仍然无法正常工作。
  • 有什么建议吗?
  • 这对我有帮助,但我还想在 Xcode 13.0 中补充一点,SwiftUI 项目由于某种原因不会自动生成 info.plist 文件。因此,如果您在选择项目的目标后转到信息选项卡,您将能够编辑数组并使其工作。
【解决方案2】:

我遇到了同样的问题(在物理设备中)。在 iPhone 上它工作正常,但在 iPad 上它不工作。解决方案是调整两者的“设备”选项,在本例中为“横向”。

【讨论】:

    【解决方案3】:

    我有同样的问题,花了我一整天的时间,我通过这样做解决了: 覆盖 AppDelegate 方法

        func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
            
    
            if self.allowOrentitaionRotation {
                return .allButUpsideDown;
            }
            return .portrait;
        }
    

    【讨论】:

      【解决方案4】:

      在我的情况下(Xcode 13.1),它非常适合我:

      按照步骤:

      1. 选择你的目标;
      2. 选择Build Settings
      3. 选择AllCombined 选项;
      4. 搜索orientation关键字
      5. 注意Supported interface Orientations(iPhone),点击右边的值;
      6. 删除不需要的方向。

      【讨论】:

      • 这很好用。我尝试使用取消选择在“常规”选项卡上禁用它,但它不起作用,它们仍保留在构建设置上。在构建设置中,我删除了它们并且效果很好。谢谢。
      • 这就像一个魅力。无需添加到 Info.plist 也无需在代码中覆盖。感谢@zephyr
      猜你喜欢
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多