Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supportedInterfaceOrientations in iOS 10 and swift 2.3

Tags:

ios10

swift

I am using Xcode 8 GM and have an old project that need updating for iOS 10.

I have found that my current appstore build using version 2.2 of Swift is not supporting the desired interfaceorientation functionality when running on iOS 10

Simply put when I override supportedInterfaceOrientations() it never gets called when running on iOS 10.

On previous versions it works fine.

I can see that the signature has changed so that supportedInterfaceOrientations is now a var and not a method but this only seem to apply to Swift 3 and not to Swift 2.3. When I try to override as a var in Swift 2.3 it will not compile and if I use the old signature it never gets called under iOS 10

Any ideas?

like image 682
blackpool Avatar asked Sep 13 '16 19:09

blackpool


2 Answers

Try on this way:

1) Create a custom NavigationController

CustomNavigationController.swift:

class CustomNavigationController: UINavigationController, UINavigationControllerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    internal override func shouldAutorotate() -> Bool {
        return visibleViewController!.shouldAutorotate()
    }

    internal override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
      if(visibleViewController?.supportedInterfaceOrientations() != nil){
        return (visibleViewController?.supportedInterfaceOrientations())!
      }else{
        return UIInterfaceOrientationMask.Portrait
      }
    }
}

2) When you want to Override on an ViewController.swift:

override internal func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape]
    return orientation
}

override internal func shouldAutorotate() -> Bool {
        return false;
    }
like image 102
Gent Avatar answered Nov 07 '22 22:11

Gent


For ios 10, Swift 3.0

override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.all
    }
like image 24
LuAndre Avatar answered Nov 07 '22 22:11

LuAndre