Home > other >  How to disable app orientation in Xcode 13 (swift 5 )?
How to disable app orientation in Xcode 13 (swift 5 )?

Time:05-22

How to lock app orientation to a specific mode in Xcode 13?

CodePudding user response:

1. Lock orientation to a specific mode i.e Portrait

In your AppDelegate, take a variable as

var restrictRotation:UIInterfaceOrientationMask = .portrait

and paste this override function

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask{
        return self.restrictRotation
    }

2. Lock orientation for a UIViewController

In your AppDelegate, take a variable as

var restrictRotation:UIInterfaceOrientationMask = .all

and paste this override function

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask{
        return self.restrictRotation
    }

And very importantly call the below line from viewWillAppear or viewDidLoad method

(UIApplication.shared.delegate as! AppDelegate).restrictRotation = .portrait

CodePudding user response:

enter image description here

Here's a screenshot of Xcode. This UI is where you can define it globally, or you can do it programmatically, as already someone else has answered.

Additionally, you can configure the iPad here in Target -> build settings enter image description here

  • Related