First of all, this isn\'t a duplicate. I\'ve looked at all of the questions related to this on SO and none of them work for me. Hopefully it\'s just because I\'m new to iOS
In my case I have the view controller embedded in a navigation controller, and most of the solutions don't work because the viewcontroller depends on the navigation controller orientation. For this when you create the instance of the view controller you have to cast it to UINavigationController :
let theViewController = UIViewController()
if let navController = theViewController as? UINavigationController {
navController.delegate = self
}
And then add this extension: extension PlaySplashViewController: UINavigationControllerDelegate {
func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
}
In this case this going to set portrait orientation for the navigation controller so the view controller going to use this orientation too.