Loading a Welcome Screen (Splash Screen) before TabBarController

后端 未结 5 1427
不知归路
不知归路 2020-12-08 09:11

In my TabBar based iPhone application, I would like to display a full screen welcome page (with some logs) before the actual application loads, How can I load a UIView from

相关标签:
5条回答
  • 2020-12-08 09:15

    In one of my tab-bar apps, I display a splash screen like so:

    In my app delegate object, I start displaying it in didFinishLaunchingWithOptions

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        splashScreenVC = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenView" bundle:nil];
    
        [window addSubview:splashScreenVC.view];
        [window makeKeyAndVisible];
    
        //set delay before showing new screen
        [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(onSlashScreenExpired:) userInfo:nil repeats:NO];
    
        return YES;
    }
    

    The onSlashScreenExpired method looks like:

    - (void)onSlashScreenExpired:(id)userInfo{
        [splashScreenVC.view removeFromSuperview];
        [splashScreenVC release];
    
        // At this point, create the tab bar controller and display it
    }
    

    I'm fairly certain I cobbled this together from another question on SO, but I can't find it.

    0 讨论(0)
  • 2020-12-08 09:17

    I add a subView to the main window in the appDelegate:

    LoginViewController *loginController = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                                                                 bundle: nil];
    [window addSubview: [loginController view]];
    

    Then in the LoginViewController, when I'm ready to dismiss the View (to show YOUR tabController say) I do:

    UIView *currentView = self.view;
    UIView *theWindow = [currentView superview];
    
    [currentView removeFromSuperview];
    
    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromBottom];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
    [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
    
    0 讨论(0)
  • 2020-12-08 09:28
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    {    
        splashView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image01.png"]];
        splashView.frame=CGRectMake(0,21,320,460);
        [self.window makeKeyAndVisible];
        [self.window addSubview:splashView];
    
    
        [self performSelector:@selector(splashremove) withObject:nil afterDelay:10.5];
        [self performSelector:@selector(sixthimage) withObject:nil afterDelay:9.0];
        [self performSelector:@selector(fifthimage) withObject:nil afterDelay:7.5];
        [self performSelector:@selector(fourthimage) withObject:nil afterDelay:6.0];
        [self performSelector:@selector(thirdimage) withObject:nil afterDelay:4.5];
        [self performSelector:@selector(secondimage) withObject:nil afterDelay:3.0];
        [self performSelector:@selector(firstimage) withObject:nil afterDelay:1.5];
    
    
       return YES;
    }
    
    -(void)firstimage
    {
        NSLog(@"Inside first image");
        splashView.image=[UIImage imageNamed:@"image01.png"];
    }
    
    
    -(void)secondimage
    {
        NSLog(@"Inside second image");
        splashView.image=[UIImage imageNamed:@"image02.png"];
    }
    
    
    
    -(void)thirdimage
    {
        NSLog(@"Inside third image");
        splashView.image=[UIImage imageNamed:@"image03.png"];
    }
    
    
    
    -(void)fourthimage
    {
        NSLog(@"Inside fourth image");
        splashView.image=[UIImage imageNamed:@"image04.png"];
    }
    
    
    
    -(void)fifthimage
    {
        NSLog(@"Inside fifth image");
        splashView.image=[UIImage imageNamed:@"image05.png"];
    }
    
    
    
    -(void)sixthimage
    {
        NSLog(@"Inside sixth image");
        splashView.image=[UIImage imageNamed:@"image06.png"];
    
    
    }
    
    -(void)splashremove
    {
        NSLog(@"Inside splashremove image");
    
        [splashView removeFromSuperview];
        [splashView release];
    
        [self.window addSubview:tabBarController.view];
        [self.window makeKeyAndVisible];
    
    }
    
    0 讨论(0)
  • 2020-12-08 09:36

    The right way to do this would be to load your tab bar application normally, but use the presentModalViewController:animated: method of the tab bar controller to display a view controller over it (in application:didFinishLaunching:):

    SplashScreenController *controller = [[SplashScreenController alloc] initWithNibNamed:nil bundle:nil];
    [self.tabBarController presentModalViewController:controller animated:YES];
    [controller release];
    

    I'll usually put a "dismiss" button on the splash screen, but you could also do something like this:

    [self.tabBarController performSelector:@selector(dismissModalViewControllerAnimated:) withObject:YES afterDelay:2.0];
    

    which will present the view controller at launch and dismiss it after two seconds. Change the YESes to NOs to avoid the slide-up-from-the-bottom animation.

    0 讨论(0)
  • 2020-12-08 09:42

    The UI guidelines say you shouldn't have a splash screen - you should present a dummy version of the view the user will see when the application loads, without any data in it:

    see Apple iPhone UI Guidelines on Launch Images for details - here's an excerpt:

    To enhance the user’s experience at application launch, you should provide a launch image. A launch image looks very similar to the first screen your application displays. iPhone OS displays this image instantly when the user taps your application icon on the Home screen. As soon as it’s ready for use, your application displays its first screen, replacing the launch placeholder image.

    It’s important to emphasize that the reason to supply a launch image is to improve user experience; it is not an opportunity to provide:

    • An “application entry experience,” such as a splash screen
    • An About window
    • Branding elements, unless they are a static part of your application’s first screen
    0 讨论(0)
提交回复
热议问题