我正在使用Storyboard开发一个Swift应用程序,它由一个UITabBarController、一个UINavigationController和三个UIViewController组成。
TabBarController -> NavigationController -> ViewController1 -> VC2 -> VC3
我希望构建应用程序时,前两个视图控制器只能以纵向方式显示,而第三个只能以LandscapeRight方式显示。
我创建了UITabBarController的一个子类:
当我启动应用程序时,前两个视图控制器被锁定在纵向模式下,而第三个视图控制器不是横向模式,而是纵向模式。只有当我将设备旋转到横向模式时,界面才会旋转到正确的位置。我该如何解决这个问题?
此外,当我尝试使用返回按钮返回导航栏的第二个视图控制器时,页面仍然被锁定,并且我收到以下错误:Unbalanced calls to begin/end appearance transitions for <_TtC11AppNamem6Detail: 0x145ab3a0>。
TabBarController -> NavigationController -> ViewController1 -> VC2 -> VC3
我希望构建应用程序时,前两个视图控制器只能以纵向方式显示,而第三个只能以LandscapeRight方式显示。
我创建了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)
}
对于 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)
}
}
在自定义的视图控制器中,我添加了以下方法:
override func shouldAutorotate() -> Bool{
// This method is the same for all the three custom ViewController
return true
}
override func supportedInterfaceOrientations() -> Int{
// Portrait for the first 2 ViewController
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
// LandscapeRight for the third
return Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
}
当我启动应用程序时,前两个视图控制器被锁定在纵向模式下,而第三个视图控制器不是横向模式,而是纵向模式。只有当我将设备旋转到横向模式时,界面才会旋转到正确的位置。我该如何解决这个问题?
此外,当我尝试使用返回按钮返回导航栏的第二个视图控制器时,页面仍然被锁定,并且我收到以下错误:Unbalanced calls to begin/end appearance transitions for <_TtC11AppNamem6Detail: 0x145ab3a0>。