简短的回答是,你不能因为根据Apple docs here
系统将视图控制器支持的方向与应用程序支持的方向(由Info.plist文件或应用程序委托的应用程序(_:supportedInterfaceOrientationsFor :)方法确定)和设备支持的方向相交,以确定是否旋转。
要实现所需,您还应将允许的方向设置为横向,然后在视图控制器中实现以下内容以允许纵向或横向(或两者):
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait//or UIInterfaceOrientationMask.landscape
}
然后,要强制使用特定方向,您可以将方向设置为UIDevice:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")