锁定屏幕方向为肖像 - ios swift

时间:2016-02-09 06:34:29

标签: ios iphone swift screen-orientation

我正在创建一个仅支持纵向模式的应用程序。我不希望风景或人像颠倒。我尝试了一些代码。这允许我锁定纵向模式。

我正在使用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:

我的设置文件 enter image description here

2 个答案:

答案 0 :(得分:28)

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

enter image description here

另请查看info.plist。确保Supported Interface Orientations仅包含一个值(纵向)。有时它从设置中删除但未在plist文件中更新。

enter image description here

答案 1 :(得分:3)

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

如果这不能解决问题,请在info.plist中添加支持的界面方向数组类型的键。和String项目到该数组的值为纵向(底部主页按钮)

enter image description here

相关问题