How to lock app orientation to a specific mode in Xcode 13?
2
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
UIViewController
var restrictRotation:UIInterfaceOrientationMask = .all
And very importantly call the below line from viewWillAppear or viewDidLoad method
viewWillAppear
viewDidLoad
(UIApplication.shared.delegate as! AppDelegate).restrictRotation = .portrait
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
Click here to cancel reply.
2
Answers
1. Lock orientation to a specific mode i.e Portrait
In your AppDelegate, take a variable as
and paste this override function
2. Lock orientation for a
UIViewController
In your AppDelegate, take a variable as
and paste this override function
And very importantly call the below line from
viewWillAppear
orviewDidLoad
methodHere’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