ios - 斯威特4。初始 ViewController 一瞬间错误,然后修复

标签 ios uiviewcontroller swift4

在我的应用程序中,第一次使用该应用程序时,用户会被带到一个特定的 View Controller (TutorialPageViewController)。每次使用它时,用户都会被带到不同的 View Controller (HomeViewController)。

为此,我创建了第三个 View Controller (FirstBlankViewController),我在其中显示应用程序的 Logo 一秒钟。在那一秒之后,我调用了适当的 View Controller 。这是可行的,但是当应用程序打开时,一瞬间,您会看到错误的 View Controller (即 TutorialPageViewController 或 HomeViewController),然后第一个打开,一秒钟后它会做正确的事情。

但是为什么在设置为初始 View Controller 的 FirstBlankViewController 之前出现任何东西。它不应该出现,哪怕是一瞬间。

这是 FirstBlankViewController 中的代码:

 override func viewDidLoad() {
    super.viewDidLoad()


    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {

        let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")


        if launchedBefore  {

            print("Not first launch.")
            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let newViewController = storyBoard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
            self.present(newViewController, animated: false, completion: nil)

        } else {
            print("First launch")
            self.dismiss(animated: false)
            let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let newViewController = storyBoard.instantiateViewController(withIdentifier: "TutorialPageViewController") as! TutorialPageViewController

            self.present(newViewController, animated: false, completion: nil)
        }

    })

}

希望一切顺利!

谢谢

最佳答案

闪烁是 每个应用 都会发生的 iOS 错误/功能,包括系统应用程序。它是一个缓存系统,显示来自应用程序的屏幕截图。它试图复制应用程序的最后状态,但是,它远非完美。请注意,无论您是否设置了启动屏幕/启动图像,都会发生闪烁。

忽略它并继续前进。

关于ios - 斯威特4。初始 ViewController 一瞬间错误,然后修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370017/

相关文章:

iOS8 和 BTLE | CBCentralManager 无法找到外围设备

iphone - 当UIImage不存在时如何显示UILabel

iphone - 返回使用 GCD 在单独线程中检索到的值

iOS 7 - 隐藏 subview Controller 上的状态栏

ios - 调用 Storyboard 场景而不在 swift 中创建 segue?

ios - 在显示VC代码不起作用后删除VC

swift4 - 谷歌地图奇怪的行为 swift 4 ios

ios - 将不同的 Google 地点类别归为一类

ios - 如何在 String Swift4 中交换两个字符?

iphone - iO 中的矢量图形?