【发布时间】:2019-11-26 15:58:30
【问题描述】:
我现在搜索了一天,没有找到合适的解决方案。 我的应用程序由内部的标签栏控制器和导航控制器组成。 我只希望所有屏幕都是纵向的,但只有一个子视图是横向的。
它可以到达那里,但是当我从子视图返回时,物理上保持横向,尽管我只允许 .portrait ind 控制器,但父视图也显示为横向。
我已经这样做了:
extension UITabBarController {
override open var shouldAutorotate: Bool {
get {
if let visibleVC = selectedViewController {
return visibleVC.shouldAutorotate
}
return super.shouldAutorotate
}
}
override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
get {
if let visibleVC = selectedViewController {
return visibleVC.preferredInterfaceOrientationForPresentation
}
return super.preferredInterfaceOrientationForPresentation
}
}
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
// your custom logic for rotation of selected tab
get {
if let visibleVC = selectedViewController {
return visibleVC.supportedInterfaceOrientations
}
return super.supportedInterfaceOrientations
}
}
}
extension UINavigationController {
override open var shouldAutorotate: Bool {
get {
if let visibleVC = visibleViewController {
return visibleVC.shouldAutorotate
}
return super.shouldAutorotate
}
}
override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
get {
if let visibleVC = visibleViewController {
return visibleVC.preferredInterfaceOrientationForPresentation
}
return super.preferredInterfaceOrientationForPresentation
}
}
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{
get {
if let visibleVC = visibleViewController {
return visibleVC.supportedInterfaceOrientations
}
return super.supportedInterfaceOrientations
}
}
}
在父控制器中:
override var shouldAutorotate: Bool{
return true
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
return .portrait
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
return .portrait
}
当我将设备转到纵向时,视图再次以纵向显示,但我希望在孩子以横向方式解雇后立即发生这种情况,即使我不转动设备。
有什么想法吗? 谢谢!
【问题讨论】:
标签: ios swift xcode uiviewcontroller