首页 > 解决方案 > AppDelegates 函数“supportedInterfaceOrientationsFor”不会在 iPad 上调用

问题描述

在我的 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 也设置为“仅限横向”,但应用程序无论如何都以纵向模式启动,这也很奇怪:

信息列表

标签: swiftxcodeswiftui

解决方案


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

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

或在您的项目中 > 常规

在此处输入图像描述


推荐阅读