我的整个应用是纵向模式。但是,一个屏幕需要能够旋转到横向(用于播放视频)。我可以启用所有方向旋转而没有问题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()
效果很好great ..问题是当我尝试将其改回到仅纵向模式时。
我正在尝试此操作,因为视频视图控制器已关闭:
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UINavigationController.attemptRotationToDeviceOrientation()
..但如果当前将视频视图控制器旋转到横向,则它不会触发上述AppDelegate的supportedInterfaceOrientationsForWindow函数。有趣的是,如果视频视图控制器当前旋转到纵向,它会将触发功能。
所以我想知道如何设置我的一个视图控制器具有all方向,然后将其改回为纵向?
您是否尝试覆盖控制器中的supportedInterfaceOrientations
?这可能会有帮助。
示例:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all
}
返回视图控制器支持的所有界面方向。