Disable Orientation Change in iOS


There are numerous application which either runs on Portrait mode or in Landscape mode.

Restricting the application in one of the mode is important to achieve this.

In this post we will see how to restrict the orientation or disable the orientation to one mode.

If you want the application to be running only in Portrait mode,

Below your viewDidLoad method copy the below line of code

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
   get {
      return .portrait
   }
}

This will lock the landscape mode for your application. Similarly by replacing .portrait to .landscape will run your application in landscape mode.

If not specified your application will run on both mode.

Alternatively you can lock the orientation from Xcode Builder as shown below.

raja
Published on 07-Aug-2019 17:43:36
Advertisements