iOS 8 upside down orientation, XCode option enabled, still doesn't work
Asked Answered
C

3

20

I have a universal application being developed in iOS8 (XCode 6.1.1). It will support all the 4 orientations (left, right, portrait & upside down).

The problem is that, although in XCode the four options for supported orientations are checked, only left, right & portrait are working properly. So, is there a bug on XCode or iOS8? My info.plist shows all the supported orientations, but when I run the app on simulator or on the device it doesn't 'flip' the orientation when it's upside down. (PS: it's an singleview app, it doesn't have any navigation controller).

Thanks!

Cleverson

Chita answered 17/12, 2014 at 12:28 Comment(0)
C
15

Well, I have figured out the purpose of the the options on project configuration... Within the options you're saying "my app support these orientations" and not "my app must use these four options"... So, on iPhone you must explicity say that a particular ViewController support all orientations (the upsidedown doesn't make parte of the default orientations, for a reason that I dont know)... The code should be like this for supporting all orientations:

override func supportedInterfaceOrientations() -> Int{
    return Int(UIInterfaceOrientationMask.All.rawValue)
}
Chita answered 17/12, 2014 at 12:58 Comment(2)
Does not work as of iOS 9 beta (Xcode beta 4) - even though I fixed the signature to return a value of type UIInterfaceOrientationMask (otherwise it won't compile).Curitiba
Doesn't work on Xcode 9, looks like the function is totally gone.Megaera
F
13

With Swift 2.1, you can simplify @Cleversou’s answer to:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
{
  return .All
}

With Swift 2.3

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
  return .all
}
Ferret answered 29/10, 2015 at 10:25 Comment(1)
Fascinating, thanks. Interestingly, it seems you only have to do that on YOUR HIGHEST-LEVEL VIEW CONTROLLER. You'd think, you have to do it "all the way down".Levorotatory
S
13

If you are running inside of a navigation controller or tab bar controller, you will need to do the same override in your subclass or override all instances with an extension:

extension UINavigationController {
  override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .All
  }
}

extension UITabBarController {
  override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .All
  }
}

Edit: as of Swift 3.0 / iOS 9 (and possibly earlier) this would be:

extension UINavigationController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}

extension UITabBarController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}
Skedaddle answered 1/5, 2016 at 16:7 Comment(2)
Great. But does not seem to apply to launch screen.Enthetic
Thanks! I added a NavigationController to my very first ViewController that should only support portrait mode, which broke it. Extending UINavigationController fixed it BUT afterwards it applied to every other NavigationController too! If you only want to use custom settings for a specific NC, create a new class myNavigationController: UINavigationController {} class with the special code inside, then set it as custom class for the NC in the inspector.Inositol

© 2022 - 2024 — McMap. All rights reserved.