0

Introduction
I currently have to Storyboards in my project, with one of them being the app's tutorial set in a pageView controller and the second one being the actual app's storyboard. Currently the tutorial only appears on initial app launch (as expected), but I actually have to kill the app, and reopen it for the main app view to appear.

Attempt(s)
I've tried programmatically loading the main app's viewController in the tutorial's pageView controller which does work, but is in no way smooth or elegant. The way I did it is similar to the code I posted here

Question
How would I go about fluidly transitioning between two Storyboard viewControllers? What would be the most appropriate way of transitioning between them? What documentations should I read? Thanks in advance!

Community
  • 1
  • 1
cyril
  • 3,020
  • 6
  • 36
  • 61

2 Answers2

0

I would suggest presenting your main view as usual, and (for the first launch) presenting your tutorial view modally. This is a clear interaction pattern; both the presentation animation and the dismiss animation will make sense to the user.

Alternately, you can present the tutorial view modally, with animate:NO to prevent a potentially awkward transition.

The code is rather simple. Just load up your main view as usual, and then present the modal view if appropriate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Load main view
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"firstView"]; // determine the initial view controller here 
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

    if (self.isFirstLaunch)
    {
        // Display tutorial
        UIStoryboard *tutorialStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
         UIViewController *tutorialViewController = [tutorialStoryboard instantiateViewControllerWithIdentifier:@"firstTutorialView"];
        [self.window.rootViewController presentViewController:tutorialViewController animated:NO completion:nil];
    }
}
emma ray
  • 13,336
  • 1
  • 24
  • 50
  • Thanks I'll try this when I get home! – cyril Dec 06 '14 at 19:19
  • In this case you get warning about unbalanced appearance call in console. For now it it is not an issue, but in future can cause more problems. `2014-12-09 18:13:40.518 Test[5964:197973] Unbalanced calls to begin/end appearance transitions for .` – Vitalii Gozhenko Dec 09 '14 at 16:14
-1

In this case you get issue about presenting modal view controller (tutorial) from view controller (root), which isn't displayed and loaded yet. I use direct replacement of rootViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    if (self.isFirstLaunch) {
        UIStoryboard *tutorialStoryboard = [UIStoryboard storyboardWithName:@"Tutorial" bundle:nil];
        self.window.rootViewController = [tutorialStoryboard instantiateInitialViewController];

    } else {
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
        self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

- (void)closeTutorial
{
    // This is solution without animation
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainScreen" bundle:nil];
    self.window.rootViewController = [mainStoryboard instantiateInitialViewController];

    // This is solution with animation
    [self.window.rootViewController presentViewController:[mainStoryboard instantiateInitialViewController] animated:YES completion:nil];
}
Vitalii Gozhenko
  • 9,220
  • 2
  • 48
  • 66