我想将所有ViewController中的方向锁定为纵向,但其中之一除外,当将其始终压在landscapeRight中时。
我尝试了许多解决方案,使用了UINavigationController
扩展名,覆盖了supportedInterfaceOrientations
和shouldAutorotate
,但是没有运气。
最佳答案
我已经找到了解决方案,目前它正在运行。
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
在另一种实现相同的方法,但具有纵向方向。
UINavigationController
的扩展名open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
open override var shouldAutorotate: Bool {
return true
}
注意:还要在Project的目标中启用所有需要的支持
方向。
我想以横向模式展示的唯一一个控制器以模态展示。