【发布时间】:2020-02-04 05:09:28
【问题描述】:
我的整个应用都是纵向模式。但是,一个屏幕需要能够旋转到横向(用于播放视频)。我能够毫无问题地启用所有方向旋转via @Jonathan Danek's answer。
在我的 AppDelegate 中有:
static var orientationLock = UIInterfaceOrientationMask.portrait
随后:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return AppDelegate.orientationLock
}
因此,为了启用所有方向的旋转,我在显示视频视图控制器时执行以下操作:
AppDelegate.orientationLock = UIInterfaceOrientationMask.all
UINavigationController.attemptRotationToDeviceOrientation()
这很好用???? ..问题是当我尝试将其改回为仅纵向模式时。
我正在尝试这个,因为视频视图控制器被解除:
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UINavigationController.attemptRotationToDeviceOrientation()
..但如果视频视图控制器当前旋转为横向,则不会触发上述 AppDelegate 的 supportedInterfaceOrientationsForWindow 功能。有趣的是,如果视频视图控制器当前旋转为纵向,它将触发该功能。
所以我想知道如何将我的一个视图控制器设置为具有所有方向,然后将其更改回仅纵向?
【问题讨论】:
-
如果答案有帮助,试试这个:stackoverflow.com/a/45351231/2781088。
-
我通过@bmjohns answered here的路线解决了这个问题
标签: ios uikit device-orientation