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?
Asked
Active
Viewed 193 times
0
-
2Does this answer your question? [How to lock orientation of one view controller to portrait mode only in Swift](https://stackoverflow.com/questions/28938660/how-to-lock-orientation-of-one-view-controller-to-portrait-mode-only-in-swift) – Amr Sep 06 '21 at 03:22
1 Answers
-1
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
}

Gautham
- 1
- 1