locking屏幕的方向 – ios swift

我正在创build一个只支持纵向模式的应用程序。 我不想横向或纵向颠倒。 我试了一些代码。 这使我可以locking肖像模式。

我正在使用navigationcontroller和presentviewcontroller。 现在我的问题是:1.如果我颠倒了我的设备,并打开我的应用程序打开倒置模式是错误的。 2.我点击一些button,进入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:

我的设置文件 在这里输入图像说明

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

在这里输入图像说明

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

在这里输入图像说明

如果您的应用程序不支持拆分屏幕视图,则应选中要求全屏的选项。 这解决了我的肖像模式的问题。 在这里输入图像说明

如果这不能解决问题,请在您的info.plist中添加受支持的接口方向数组types的Key。 和string项目的值与数组肖像(底部主页button)

在这里输入图像说明