title: Lock screen Orientation to portrait - ios swift
body: <p>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.</p>
  
  <p>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. </p>
  
  <p><strong>I want all the navigationcontroller and presentviewcontroller in portrait mode</strong></p>
  
  <p>My codes:</p>
  
  <p>I set device orientarion portrait in <code>Target -&gt; General -&gt; Deployment Info -&gt; Portrait</code></p>
  
  <p><strong>In my appdelagate.swift:</strong></p>
  
  <pre><code>func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -&gt; UIInterfaceOrientationMask {
          return UIInterfaceOrientationMask.Portrait
      }
  </code></pre>
  
  <p>In my First view controller. Which is basically child of Navigation Controller</p>
  
  <pre><code>override func shouldAutorotate() -&gt; Bool {
  
  
              return false
          }
  
          override func supportedInterfaceOrientations() -&gt; UIInterfaceOrientationMask {
              return [UIInterfaceOrientationMask.Portrait ]
          }
  </code></pre>
  
  <p>Edit 1:</p>
  
  <p>Also I set <code>StoryBoard -&gt; ViewController -&gt; Attribute Inspector -&gt; Orientation -&gt; Portrait</code> </p>
  
  <p>Edit 2:</p>
  
  <p>My settings file 
  <a href="https://i.stack.imgur.com/N4RzP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/N4RzP.png" alt="enter image description here"></a></p>