iOS在没有闪存的情况下启动模态视图控制器

问题描述:

我想在初次启动时向用户提供一个教程向导。

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

有没有办法提出模态 UIViewController 在应用程序启动时,没有看到,至少在一毫秒内,它后面的 rootViewController

Is there a way to present a modal UIViewController on application startup, without seeing, at least for a millisecond, the rootViewController behind it?

现在我正在做这样的事情(为了清楚起见,省略了首次启动检查):

Now I'm doing something like this (omitting first-launch checks for clarity):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // ...

    UIStoryboard *storyboard = self.window.rootViewController.storyboard;
    TutorialViewController* tutorialViewController = [storyboard instantiateViewControllerWithIdentifier:@"tutorial"];
    tutorialViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self.window makeKeyAndVisible];
    [self.window.rootViewController presentViewController:tutorialViewController animated:NO completion:NULL];
}

没有运气。我试图将 [self.window makeKeyAndVisible]; 移到 [... presentViewController:tutorialViewController ...] $ c之前$ c>语句,但是模态甚至没有出现。

with no luck. I've tried to move [self.window makeKeyAndVisible]; to before the [... presentViewController:tutorialViewController ...] statement, but then the modal doesn't even appear.

所有presentViewController方法都要求呈现视图控制器先出现了。为了隐藏根VC,必须呈现覆盖。启动屏幕可以继续显示在窗口上,直到演示文稿完成,然后逐渐淡出叠加层。

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];
    }];
}];