【问题标题】:Can't force rotate of orientation in landscape mode无法在横向模式下强制旋转方向
【发布时间】: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 功能。有趣的是,如果视频视图控制器当前旋转为纵向,它触发该功能。

所以我想知道如何将我的一个视图控制器设置为具有所有方向,然后将其更改回仅纵向?

【问题讨论】:

标签: ios uikit device-orientation


【解决方案1】:

您是否尝试过覆盖控制器中的supportedInterfaceOrientations?这可能会有所帮助。

例子:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.all
}

返回视图控制器支持的所有界面方向。

Apple Doc - supportedInterfaceOrientations

Swift 5.1 短版:

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    .all
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    相关资源
    最近更新 更多