Reputation: 31
I am trying to lock my viewController
to just portrait orientation without having to rely on Deployment Info but my following code isn't working
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return UIInterfaceOrientation.portrait
}
override func viewDidLoad() {
super.viewDidLoad()
}
Upvotes: 2
Views: 6600
Reputation: 79
You can try this in the AppDelegate. This will lock the orientation for all your viewControllers
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
Upvotes: 6
Reputation: 451
Make sure you put your code in parent view Controller otherwise it may not work, for example, in the navigation controller view controller class.
Upvotes: 1