Lock screen Orientation to portrait - ios swift

微笑、不失礼 提交于 2019-12-03 17:41:32

问题


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.

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.

I want all the navigationcontroller and presentviewcontroller in portrait mode

My codes:

I set device orientarion portrait in Target -> General -> Deployment Info -> Portrait

In my 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 ]
        }

Edit 1:

Also I set StoryBoard -> ViewController -> Attribute Inspector -> Orientation -> Portrait

Edit 2:

My settings file


回答1:


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

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.




回答2:


If your app is not supporting split screen view than you should check the option to Require full screen. This fixed my issue with portrait mode.

If this does not resolve issue add Supported interface orientations Key of Array type in your info.plist. And String item to that array with value Portrait (bottom home button)



来源:https://stackoverflow.com/questions/35285392/lock-screen-orientation-to-portrait-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!