Swift 3 & 4
Set the supportedInterfaceOrientations
property of specific UIViewControllers like this:
class MyViewController: UIViewController {
var orientations = UIInterfaceOrientationMask.portrait //or what orientation you want
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
get { return self.orientations }
set { self.orientations = newValue }
}
override func viewDidLoad() {
super.viewDidLoad()
}
//...
}
UPDATE
This solution only works when your viewController
is not embedded in UINavigationController
, because the orientation inherits from parent viewController.
For this case, you can create a subclass of UINavigationViewController
and set these properties on it.