热门标签 | HotTags
当前位置:  开发笔记 > IOS > 正文

SwiftUIBeta3黑屏

如何解决《SwiftUIBeta3黑屏》经验,为你挑选了1个好方法。

我刚刚转换为Beta 3,以前使用的SwiftUI代码现在正在呈现纯黑屏幕。Beta 3是否发生了变化,从而导致了此问题?有解决方案吗?

场景委托代码:

    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()

    }

David L.. 21

场景Delgate的Beta 3工作版本:

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帖子的答案。


为了澄清,使用的beta 1 UIWindow(frame: ...)现在已更改为UIWindow(windowScene: ...)。现在,传递的参数是当前场景,并类型转换为UIWindowScene



1> David L..:

场景Delgate的Beta 3工作版本:

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帖子的答案。


为了澄清,使用的beta 1 UIWindow(frame: ...)现在已更改为UIWindow(windowScene: ...)。现在,传递的参数是当前场景,并类型转换为UIWindowScene


推荐阅读
author-avatar
鲁野山人2602886435
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有