【问题标题】:SwiftUI iPad app shows black screen on enabling multiple window supportSwiftUI iPad 应用程序在启用多窗口支持时显示黑屏
【发布时间】:2019-11-12 13:44:13
【问题描述】:

在 macOS Catalina 上使用 SwiftUI,当启用“支持多个窗口”时,我的 iPad 应用在模拟器中启动时显示黑屏

我正在使用股票 SwiftUI 项目,唯一的变化是单击“支持多个窗口”复选框

这是来自我的 SceneDelegate,我认为这是在 SwiftUI 中设置窗口的正确方法

var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}

在我的 Info.plist 中,我相信我拥有所需的一切

<key>UIApplicationSceneManifest</key>
    <dict>
        <key>UIApplicationSupportsMultipleScenes</key>
        <true/>
        <key>UISceneConfigurations</key>
        <dict>
            <key>UIWindowSceneSessionRoleApplication</key>
            <array>
                <dict>
                    <key>UILaunchStoryboardName</key>
                    <string>LaunchScreen</string>
                    <key>UISceneConfigurationName</key>
                    <string>Default Configuration</string>
                    <key>UISceneDelegateClassName</key>
                    <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                </dict>
            </array>
        </dict>
    </dict>

【问题讨论】:

  • 这不是 我的“股票 SwiftUI 项目”。有一个 if 声明嵌入了所有这些...... if let windowScene = scene as? UIWindowScene。您使用的是 Beta 2 吗?

标签: swift xcode ipad swiftui ios13


【解决方案1】:

窗口必须初始化为

let window = UIWindow(windowScene: scene as! UIWindowScene)

【讨论】:

  • objective-c 的等效项是什么?
  • window = [[UIWindow alloc] initWithWindowScene: scene]];
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多