SwiftUI Beta 3 黑屏 [英] SwiftUI Beta 3 Black Screen

查看:25
本文介绍了SwiftUI Beta 3 黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚转换为 beta 3,我以前工作的 SwiftUI 代码现在呈现纯黑屏幕.Beta 3 是否有变化导致了这种情况.有解决办法吗?

I just converted to beta 3 and my previously working SwiftUI code is now rendering a plain black screen. Was there a change in beta 3 that is causing this. Is there a solution to fix it?

场景委托代码:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

        // Use a UIHostingController as window root view controller


    let window = UIWindow(frame: UIScreen.main.bounds)


     window.rootViewController = UIHostingController(rootView: ContentView())
     self.window = window
     window.makeKeyAndVisible()

    }

推荐答案

Beta 3 工作版 Scene Delgate:

Beta 3 Working Version Of Scene Delgate:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    // Use a UIHostingController as window root view controller
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: ContentView())
        self.window = window
        window.makeKeyAndVisible()
    }
}

感谢 Reddit 帖子的回答.

澄清一下,测试版 1 使用了 UIWindow(frame: ...),现在已更改为 UIWindow(windowScene: ...).传递的参数现在是当前场景和类型转换为 UIWindowScene.

To clarify, beta 1 used UIWindow(frame: ...) which has now changed to UIWindow(windowScene: ...). The parameter passed is now the current scene and type cast to UIWindowScene.

这篇关于SwiftUI Beta 3 黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆