锁定屏幕方向为肖像 - ios swift [英] Lock screen Orientation to portrait - ios swift

查看:148
本文介绍了锁定屏幕方向为肖像 - ios swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating an application with support only for portrait mode. I don't want Landscape or Portrait upside down. I tried some code. Which allows me to lock in portrait mode.

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

I am using navigationcontroller and presentviewcontroller. Now my problem is: 1. If I rotate my device upside down and open my application it opens in upside down mode which is wrong. 2. I click some button and enter to presentviewcontroller it returns to portrait mode.

我希望所有的navigationcontroller和presentviewcontroller都处于纵向模式

我的代码:

我在目标中设置了设备方向画像 - >一般 - >部署信息 - >肖像

在我的appdelagate.swift中:

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

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

In my First view controller. Which is basically child of Navigation Controller

override func shouldAutorotate() -> Bool {


            return false
        }

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

编辑1:

此外,我设置 StoryBoard - > ViewController - >属性检查器 - >方向 - >肖像

编辑2:

我的设置文件

My settings file

推荐答案

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

Go To Target --> General and set Orientation Mode to Portrait.

同时检查info.plist。确保支持的接口方向仅包含一个值(纵向)。有时它从设置中删除但未在plist文件中更新。

Also check info.plist. Make sure Supported Interface Orientations contains only one value(Portrait). Sometime it removes from settings but not updated in plist file.

这篇关于锁定屏幕方向为肖像 - ios swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆