我需要将整个应用程序锁定在 PortraitView 中,除了一个视图控制器。我需要这些功能的功能,但同时使用这两个函数时出现错误。当我添加视图控制器功能应用程序崩溃时。如果我拿走应用程序委托,视图控制器也会做我需要的。
应用委托
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
视图控制器
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var shouldAutorotate: Bool {
return true
}
编辑为使用基本控制器视图:
我记得是否为应用程序启用了方向。需要为每个需要限制它的控制器实现定向函数。
或者,创建支持 Portrait
的基本 UIViewController 应由所有控制器继承,并且仅覆盖横向控制器中的方向函数。
如下所示:
class BaseViewController : UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .Portrait...
}
}
class ViewController1: BaseViewController {
// nothin to override
}
class LandscapeController: BaseViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
}