在将视图控制器设置为横向时在 App Delegate 中锁定纵向视图
Lock Portrait View in App Delegate while having View controller as landscape
我需要将整个应用程序锁定在 PortraitView 中,一个视图控制器除外。我需要这些功能的功能,但同时使用这两个功能时出现错误。当我添加视图控制器功能时,应用程序崩溃。如果我拿走应用程序委托,视图控制器也会做我需要的。
应用代理
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
ViewController
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var shouldAutorotate: Bool {
return true
}
编辑为使用基本控制器视图:
我记得是否为应用程序启用了方向。需要为每个需要限制它的控制器实现方向功能。
或者,创建支持 Portrait
的 Base 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
}
}
我需要将整个应用程序锁定在 PortraitView 中,一个视图控制器除外。我需要这些功能的功能,但同时使用这两个功能时出现错误。当我添加视图控制器功能时,应用程序崩溃。如果我拿走应用程序委托,视图控制器也会做我需要的。
应用代理
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}
ViewController
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var shouldAutorotate: Bool {
return true
}
编辑为使用基本控制器视图:
我记得是否为应用程序启用了方向。需要为每个需要限制它的控制器实现方向功能。
或者,创建支持 Portrait
的 Base 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
}
}