Search code examples
swiftviewdidappear

Presenting a specific view controller once immediately after launch screen closes


I have a 1-screen tutorial View Controller. I want this tutorial VC to show only once (userdefaults), but I want a smooth transition from when the launch screen finishes -> tutorial VC.

Right now - the launch screen finishes, then the main interface of the App shows for a split second, then the tutorial VC shows up. I want to remove this "flashing" of the main interface.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if !didShowTut {
        fireTutorial()
        didShowTut = true
    }
}

func fireTutorial() {
    let tutVC = UIStoryboard(name: "FirstTutorial", bundle: nil).instantiateViewController(withIdentifier: "TutorialSBID") as UIViewController
    tutVC.modalPresentationStyle = .overCurrentContext
    self.present(tutVC, animated: false, completion: nil)
}

Any help to create a smooth transition from Launch screen -> Tutorial VC would be appreciated.


Solution

  • I went with a slightly different approach to solve this.

    I embedded the main app VC in a navigation controller, then pushing the tutorialVC in App Delegate didFinishLaunchingWithOptions.

    let tutorialVC = UIStoryboard(name: "FirstTutorial", bundle: nil)
    let firstVC = tutorialVC.instantiateViewController(withIdentifier: "TutorialSBID") as UIViewController
    if let navigationController = self.window?.rootViewController as? UINavigationController
    {
        navigationController.pushViewController(firstVC, animated: false)
    }
    return true