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:
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