supportedInterfaceOrientations in iOS 10 and swift 2.3

北城余情 提交于 2019-12-06 05:31:19

问题


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?


回答1:


For ios 10, Swift 3.0

override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.all
    }



回答2:


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


来源:https://stackoverflow.com/questions/39477525/supportedinterfaceorientations-in-ios-10-and-swift-2-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!