我正在使用 Xcode 8 GM 并且有一个需要针对 iOS 10 更新的旧项目。
我发现我当前使用 Swift 2.2 版构建的应用商店在 iOS 10 上运行时不支持所需的界面定向功能
简单地说,当我覆盖 supportedInterfaceOrientations() 时,它在 iOS 10 上运行时永远不会被调用。
在以前的版本上它工作正常。
我可以看到签名已更改,因此 supportedInterfaceOrientations 现在是 var 而不是方法,但这似乎只适用于 Swift 3 而不适用于 Swift 2.3。当我尝试在 Swift 2.3 中作为 var 覆盖时,它不会编译,如果我使用旧签名,它在 iOS 10 下永远不会被调用
有任何想法吗?
试试这个方法:
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
2)当你想覆盖 ViewController.swift 时:
override internal func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
let orientation: UIInterfaceOrientationMask = [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape]
return orientation
}
override internal func shouldAutorotate() -> Bool {
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9551 次 |
| 最近记录: |