iOS Present modal view controller on startup without flash

前端 未结 9 1153
囚心锁ツ
囚心锁ツ 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:05

    It can be late but in your AppDelegate you can do this :

    //Set your rootViewController
    self.window.rootViewController=myRootViewController;
    //Hide the rootViewController to avoid the flash
    self.window.rootViewController.view.hidden=YES;
    //Display the window
    [self.window makeKeyAndVisible];
    
    if(shouldPresentModal){
    
        //Present your modal controller
        UIViewController *lc_viewController = [UIViewController new];
        UINavigationController *lc_navigationController = [[UINavigationController alloc] initWithRootViewController:lc_viewController];
        [self.window.rootViewController presentViewController:lc_navigationController animated:NO completion:^{
    
            //Display the rootViewController to show your modal
            self.window.rootViewController.view.hidden=NO;
        }];
    }
    else{
    
        //Otherwise display the rootViewController
        self.window.rootViewController.view.hidden=NO;
    }
    

提交回复
热议问题