I would like to rotate certain view controllers to portrait but not upside down, i.e the physical Home button is at the bottom. How could I do that?
CodePudding user response:
If you need a specific view controller to lock to portrait and other view controllers can have any orientation, first keep all the device orientation mode unticked (If you untick all, automatically it'll be set to all orientation) or tick all.
Then in the specific view controller where you want to keep it portrait add the below code,
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
override var shouldAutorotate: Bool {
return true
}
CodePudding user response:
Override these methods inside the targets UIViewController
subclasses:
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}