2

在我的 AppDelegate 中,我正在使用一个函数来旋转我的设备并锁定方向。

iPhone 只能是纵向的,iPad 只能是横向的。

它适用于 iPhone,但在 iPad 上永远不会调用以下函数:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    print("Test")
    return AppDelegate.orientationLock
}

我认为它在我切换到“SwiftUI Life Cicle”之前在 iPad 上工作,但我不确定这是否是它停止工作的时间点:

 @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

对于 iPad,info.plist 也设置为“仅限横向”,但应用程序无论如何都以纵向模式启动,这也很奇怪:

信息列表

4

2 回答 2

1

我也在 iPad 中遇到过这个问题,并得到了解决方案。

在您的 Info.Plist 中进行此设置。 在此处输入图像描述

或在您的项目中 > 常规

在此处输入图像描述

于 2021-02-04T10:48:05.130 回答
1

我必须在 info.plist 中将此键设置为 false,以便application(_:supportedInterfaceOrientationsFor:)在 iPad 上调用它:

<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <false/>
</dict>

感谢@lorem ipsum 的提示!

于 2021-02-04T17:22:56.260 回答