这是我的故事板的一部分,我试过但我无法处理它。
我在navigationController中尝试了什么,它没有用。你有什么建议吗?
override var shouldAutorotate : Bool {
if self.topViewController != nil{
return self.topViewController!.shouldAutorotate
}else{
return super.shouldAutorotate
}
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
if self.topViewController != nil{
return self.topViewController!.supportedInterfaceOrientations
}else{
return super.supportedInterfaceOrientations
}
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
if self.topViewController != nil{
return self.topViewController!.preferredInterfaceOrientationForPresentation
}else{
return super.preferredInterfaceOrientationForPresentation
}
}
override var preferredStatusBarStyle : UIStatusBarStyle {
return self.topViewController!.preferredStatusBarStyle
}
答案 0 :(得分:0)
您可以将此应用生命周期方法 supportedInterfaceOrientationsFor 添加到您的应用委托类中,以根据您的要求支持各种方向。
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if self.window?.rootViewController != nil {
if self.window!.rootViewController! is UITabBarController {
if self.window?.rootViewController?.childViewControllers.last is UINavigationController {
if self.window?.rootViewController?.childViewControllers.last?.childViewControllers.last is YourViewController {
return UIInterfaceOrientationMask.all;
} else {
return UIInterfaceOrientationMask.portrait;
}
} else {
if self.window!.rootViewController?.childViewControllers.last is YourViewController {
return UIInterfaceOrientationMask.all;
} else {
return UIInterfaceOrientationMask.portrait;
}
}
}
}
}