Reputation: 63
My application allows all four orientations, but the rootviewcontroller should only allow portrait orientation.
I override the supportedInterfaceOrientations method in my rootviewcontroller, but if the device is held in landscape orientation when the app launches then the view controller displayed incorrectly in landscape orientation even though only portrait orientation is allowed. This is an iOS 8 specific issue.
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.Portrait.rawValue
}
Upvotes: 0
Views: 1301
Reputation: 10286
For me implementing AppDelegate function application supportedInterfaceOrientationsForWindow did the trick
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
if let viewController = self.window?.rootViewController?.presentedViewController as? PortraitViewController{
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}else{
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}
where PortraitViewController should be replaced with the name of your root view controller class
Upvotes: 0
Reputation: 16770
In ViewController:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Swift version:
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
Upvotes: 1