3

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.

Joe
  • 3,772
  • 3
  • 33
  • 64

3 Answers3

0

You are presenting the tutVC on the viewDidAppear func which is executed after the screen has been loaded.

try calling the fireTutorial() on override func viewDidLoad() or on the override func viewWillAppear(_ animated: Bool) methods that get executed before the screen is loaded.

  • I did try that; the VC never loads up if i put fireTutorial() in either viewDidLoad or viewWillAppear. – Joe Feb 28 '18 at 06:02
  • @Joe which one is the app root view controller? – Patrick Haralabidis Feb 28 '18 at 06:17
  • The main VC is the root. I suppose for the very first App load, the tutorial VC should be root, as suggested above by Shebin? – Joe Feb 28 '18 at 06:19
  • @Joe this is probably because you are not using a navigation controller and the main VC is set as the root in the storyboard. You can add a navigation controller, set it as the entry point of your app and set the main VC as the root VC of the Navigation controller. After that you will be able to call fireTutorial in the ViewWillAppear or set up a modal segue. – Patrick Haralabidis Feb 28 '18 at 06:44
  • I've embedded my main VC in a navigation controller (in storyboard.) The TutorialVC now shows up when it's presented in viewWillAppear, but the 'flashing' is still occurring. (same result when presented in viewDidLoad). – Joe Feb 28 '18 at 07:04
  • @joe Are both view controllers in the same storyboard? If so, have you tried presenting with a seque? – Patrick Haralabidis Feb 28 '18 at 07:12
  • No, the main App interface and tutorial each have their own storyboards. – Joe Feb 28 '18 at 07:15
  • I got this working. Check my answer. Thank you for your help! You jived some ideas to try, which ultimately worked. – Joe Feb 28 '18 at 07:50
0

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
Joe
  • 3,772
  • 3
  • 33
  • 64
-1

Write this code in viewWillAppear or viewWillLayoutSubviews() instead of viewDidAppear

Bilal Awan
  • 4,730
  • 1
  • 8
  • 15