I have created an application for iPhone, using swift, that is composed from many views embedded in a navigation controller. I would like to lock the main v
Update: if you're having trouble to set orientation right after the app launches in iOS 10
, try do it in ObjC
instead of Swift
, and with class MyNavigationController: MyNavigationControllerBase
:
@implementation ABNavigationControllerBase
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
@end
Swift 3:
class MyNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}
}