ios - 为什么在 swift 5 中更改 Root View 时看不到启动(启动)屏幕?

标签 ios swift splash-screen launch

我遇到的问题是删除 Storyboard上的根箭头并在AppDelegate文件中设置 Root View 以动态更改RootView。

移动 Root View 没有问题,但现有的splashScreen(Launch Screen)不可见。为什么你看不到?如何查看 splashScreen(Launch Screen) 并转到 Root View ?

主 Storyboard

Main

登录.Storyboard,

enter image description here

启动 Storyboard

enter image description here

在 AppDelegate.swift 中移动根屏幕

var window: UIWindow?

    func switchStartUI() {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = mainStoryboard.instantiateViewController(withIdentifier: "StartViewController")
        self.window?.rootViewController = viewController
    }

    func switchToMainUI() {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = mainStoryboard.instantiateViewController(withIdentifier: "NavigationController")
        self.window?.rootViewController = viewController
    }

    func switchLoginUI(_ pushtype : String) {
        let loginStoryboard = UIStoryboard(name: "Login", bundle: nil)
        let viewController = loginStoryboard.instantiateViewController(withIdentifier: "MainLoginController") as! MainLoginController
        viewController.pushType = pushtype
        self.window?.rootViewController = viewController
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
      if let screenData : String = LocalStorage.get("ScreenView") as? String {
            switch (screenData) {
            case "success":
                switchToMainUI()
            case "success1":
                switchLoginUI("")
            case "success2":
                switchLoginUI("")
            default:
                switchStartUI()
            }
        } else {
            switchStartUI()
        }

        self.window?.makeKeyAndVisible()

        return true
    }

我想查看启动屏幕并转到 Root View

我的启动屏幕上已经有一个图像。它工作正常。但是动态修改 Root View 后我看不到闪屏。我也是这样的

我只能看到黑屏。当删除两个函数时

self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.makeKeyAndVisible()

对我来说,出现白屏,然后我进入 Root View 页面。

我不知道为什么看不到启动画面。

如何解决这个问题?

提前致谢

最佳答案

这是一个简单的解决方案。 '启动。向' Storyboard'添加了根箭头。

enter image description here

关于ios - 为什么在 swift 5 中更改 Root View 时看不到启动(启动)屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58262479/

相关文章:

javascript - x 秒后更改 HTML 页面

ios - 无法设置自定义类名

ios - 添加/删除 ViewController 作为 subview Swift 后,ParentView 属性设置为 nil

ios - 我可以在单击 TableViewCell 时将 View 更改为 ViewController 吗?

ios - 受密码保护的 UITextField 上的大写锁定图像

c# - 登录和启动画面

iOS - 是否可以通过编程方式调用电话而不显示电话号码?

swift - Firebase 配置失败 - Swift

swift - 协议(protocol)不符合自身?

javascript - React Native + 世博会 : Splash screen close after wait time and when page complete