0
votes

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
}
2

2 Answers

1
votes

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)
}
0
votes

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