【问题标题】:Lock screen Orientation to portrait - ios swift锁定屏幕方向为纵向 - ios swift
【发布时间】:2016-02-09 06:34:28
【问题描述】:

我正在创建一个仅支持纵向模式的应用程序。我不希望横向或纵向颠倒。我尝试了一些代码。这让我可以锁定纵向模式。

我正在使用navigationcontroller 和presentviewcontroller。现在我的问题是: 1. 如果我将我的设备倒置并打开我的应用程序,它会以倒置模式打开,这是错误的。 2.我点击一些按钮并进入presentviewcontroller它返回到纵向模式。

我想要纵向模式下的所有 navigationcontroller 和 presentviewcontroller

我的代码:

我在Target -> General -> Deployment Info -> Portrait中设置了设备方向图

在我的 appdelagate.swift 中:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }

在我的第一个视图控制器中。这基本上是导航控制器的孩子

override func shouldAutorotate() -> Bool {


            return false
        }

        override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
            return [UIInterfaceOrientationMask.Portrait ]
        }

编辑 1:

我也设置了StoryBoard -> ViewController -> Attribute Inspector -> Orientation -> Portrait

编辑 2:

我的设置文件

【问题讨论】:

标签: ios iphone swift screen-orientation


【解决方案1】:

转到目标 --> 常规并将方向模式设置为纵向。

同时检查 info.plist。确保Supported Interface Orientations 只包含一个值(纵向)。有时它会从设置中删除,但不会在 plist 文件中更新。

【讨论】:

  • 请按照答案中的建议检查 Info.plist 文件。您可能就是这种情况。
  • 谢谢我错过了一行,整个应用程序变得很奇怪。我是 ios 新手,谢谢。
  • 在我的情况下,iPad 有一个额外的选项允许所有方向类型。所以我只留下了Portrait (bottom home button),现在一切正常。
【解决方案2】:

如果您的应用不支持分屏视图,则应选中“要求全屏”选项。这解决了我的纵向模式问题。

如果这不能解决问题,请在 info.plist 中添加 支持的界面方向 Array 类型的键。并将值为该数组的字符串项 Portrait (bottom home button)

【讨论】:

  • 谢谢我错过了一行,整个应用程序变得很奇怪。我是ios的新手,谢谢。 Technerd 在您之前 1 分钟添加解决方案所以我接受他的回答。我投票给你。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
相关资源
最近更新 更多