14
votes

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 enter image description here

2
check this one also its working for me enter link description herePradeep Kashyap

2 Answers

37
votes

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

enter image description here

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.

enter image description here

3
votes

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. enter image description here

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)

enter image description here