我正在使用Xcode 8 GM并且有一个需要为iOS 10更新的旧项目。
我发现在iOS 10上运行时,使用Swift 2.2版的当前appstore版本不支持所需的interfaceorientation功能
简单地说,当我覆盖supportedInterfaceOrientations()时,它永远不会在iOS 10上运行时被调用。
在以前的版本中,它可以正常工作。
我可以看到签名已经改变,所以supportedInterfaceOrientations现在是var而不是方法,但这似乎只适用于Swift 3而不适用于Swift 2.3。当我尝试在Swift 2.3中覆盖为var时,它将无法编译,如果我使用旧签名,它将永远不会在iOS 10下调用
有什么想法吗?
答案 0 :(得分:4)
对于ios 10,Swift 3.0
override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all
}
答案 1 :(得分:2)
尝试这种方式:
1)创建自定义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) 如果要在ViewController.swift上覆盖:
override internal func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape]
return orientation
}
override internal func shouldAutorotate() -> Bool {
return false;
}