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?
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;
}
For ios 10, Swift 3.0
override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With