我的整个应用程序都是肖像模式。然而,一个屏幕需要能够旋转到景观(播放视频)。我能够启用所有的定向旋转,没有问题的@Jonathan Danek的回答。
在我的AppDelegate中有:
static var orientationLock = UIInterfaceOrientationMask.portrait
随后:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return AppDelegate.orientationLock
}
因此,为了支持所有方向的旋转,我在视频视图控制器中做了以下操作:
AppDelegate.orientationLock = UIInterfaceOrientationMask.all
UINavigationController.attemptRotationToDeviceOrientation()
这是一个很好的..the问题,当我试图将它更改回纵向模式时。
我正在尝试这样做,因为视频视图控制器被解职:
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UINavigationController.attemptRotationToDeviceOrientation()
如果视频视图控制器当前旋转为..but,则不会触发上述AppDelegate的supportedInterfaceOrientationsForWindow函数。有趣的是,它将触发功能,如果视频视图控制器目前旋转到肖像。
所以我想知道我怎样才能把我的一个视图控制器设置成所有的方向,然后把它改为仅仅是肖像呢?
发布于 2020-02-03 21:23:13
您是否尝试过在控制器中覆盖supportedInterfaceOrientations
?也许能帮上忙。
示例:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all
}
返回视图控制器支持的所有接口方向。
Apple supportedInterfaceOrientations
Swift 5.1短版:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
.all
}
https://stackoverflow.com/questions/60050963
复制