iOS Present modal view controller on startup without flash

前端 未结 9 1169
囚心锁ツ
囚心锁ツ 2020-12-08 00:53

I\'d like to present modally, at first startup, a tutorial wizard to the user.

Is there a way to present a modal UIViewController on application startup

9条回答
  •  心在旅途
    2020-12-08 01:04

    All presentViewController methods require the presenting view controller to have appeared first. In order to hide the root VC an overlay must be presented. The Launch Screen can continued to be presented on the window until the presentation has completed and then fadeout the overlay.

        UIView* overlayView = [[[UINib nibWithNibName:@"LaunchScreen" bundle:nil] instantiateWithOwner:nil options:nil] firstObject];
    overlayView.frame = self.window.rootViewController.view.bounds;
    overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    UIStoryboard *storyboard = self.window.rootViewController.storyboard;
    TutorialViewController* tutorialViewController = [storyboard instantiateViewControllerWithIdentifier:@"tutorial"];
    tutorialViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self.window makeKeyAndVisible];
    [self.window addSubview:overlayView];
    [self.window.rootViewController presentViewController:tutorialViewController animated:NO completion:^{
        NSLog(@"displaying");
        [UIView animateWithDuration:0.5 animations:^{
            overlayView.alpha = 0;
        } completion:^(BOOL finished) {
            [overlayView removeFromSuperview];
        }];
    }];
    

提交回复
热议问题