I am building an application quickly using a storyboard. It consists of UITabBarController, a UINavigationController and threeUIViewController`.
TabBarController → NavigationController → ViewController1 → VC2 → VC3
I want to structure the application so that the first view controller can only be in Portrait , and the third can only be in LandscapeRight .
I create a subclass for UITabBarController :
class OrientationTab: UITabBarController {
override func shouldAutorotate() -> Bool{
if self.selectedViewController != nil{
if self.selectedViewController.respondsToSelector("shouldAutorotate") {
println("TAB - shouldAutorotate - inside if")
return self.selectedViewController.shouldAutorotate()
}
}
println("TAB - shouldAutorotate - outside if")
return true
}
override func supportedInterfaceOrientations() -> Int{
if self.selectedViewController != nil{
if self.selectedViewController.respondsToSelector("supportedInterfaceOrientations"){
println("TAB - supportedInterfaceOrientations - inside if")
return self.selectedViewController.supportedInterfaceOrientations()
}
}
println("TAB - supportedInterfaceOrientations - outside if")
return Int(UIInterfaceOrientationMask.All.rawValue)
}
and for UINavigationController :
class OrientationNav: UINavigationController {
override func shouldAutorotate() -> Bool{
if self.topViewController.respondsToSelector("shouldAutorotate") {
println("NAV - shouldAutorotate - if")
return self.topViewController.shouldAutorotate()
}else{
println("NAV - shouldAutorotate - else")
return true
}
}
override func supportedInterfaceOrientations() -> Int{
if self.topViewController.respondsToSelector("supportedInterfaceOrientations"){
println("NAV - supportedInterfaceOrientations - if")
return self.topViewController.supportedInterfaceOrientations()
}else{
println("NAV - supportedInterfaceOrientations - else")
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}
in a custom ViewController . I add the following methods:
override func shouldAutorotate() -> Bool{
return true
}
override func supportedInterfaceOrientations() -> Int{
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
return Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
}
, ViewController Portrait, LandscapeRight Portrait. LandscapeRight, . ?
, ViewController BackButton, , : Unbalanced calls to begin/end appearance transitions for <_TtC11AppNamem6Detail: 0x145ab3a0>.