最佳答案
简短的回答是你不能,因为根据 Apple 文档 here
The system intersects the view controller's supported orientations with the app's supported orientations (as determined by the Info.plist file or the app delegate's application(_:supportedInterfaceOrientationsFor:) method) and the device's supported orientations to determine whether to rotate.
要实现您所需要的,您应该将允许的方向也设置为横向,然后在 View Controller 中实现以下内容以允许纵向或横向方向(或两者):
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait//or UIInterfaceOrientationMask.landscape
}
然后,要强制指定特定方向,您可以将方向设置为 UIDevice:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
关于ios - 在纵向状态下强制旋转 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52176134/