我需要将整个应用程序锁定在 PortraitView 中,一个 View Controller 除外。我需要这些功能的功能,但同时使用这两个功能时出现错误。当我添加 View Controller 功能时,应用程序崩溃。如果我拿走应用程序委托(delegate), View Controller 也会执行我需要的操作。
应用委托(delegate)
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
View Controller
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var shouldAutorotate: Bool {
return true
}
最佳答案
编辑为使用基本 Controller View :
我记得是否为应用程序启用了方向。需要为每个需要限制它的 Controller 实现方向功能。
或者,创建支持 Portrait
的 Base UIViewController。它应该被所有 Controller 继承,并且只覆盖景观 Controller 中的方向功能。
类似于以下内容:
class BaseViewController : UIViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .Portrait...
}
}
class ViewController1: BaseViewController {
// nothin to override
}
class LandscapeController: BaseViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
}
关于ios - 在将 View Controller 设置为横向时在 App Delegate 中锁定纵向 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49242471/