Loading a Welcome Screen (Splash Screen) before TabBarController

14,772

Solution 1

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.

Solution 2

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

Solution 3

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

}

Solution 4

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
Share:
14,772
shinto Joseph
Author by

shinto Joseph

Updated on June 05, 2022

Comments

  • shinto Joseph
    shinto Joseph almost 2 years

    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 xib file as the welcome screen and then from there I can load my TabBar based application.

  • shinto Joseph
    shinto Joseph over 14 years
    hai,Thanks for the quick response, i tried the code, its working, but there is a small gap in the bottom (i can see the tab bar in the background), its almost in the size of a status bar on the top. i think the view is not loading the correct origin. do you have any idea why its so ?
  • shinto Joseph
    shinto Joseph over 14 years
    hai,Thanks for the quick response, i tried the code, its working, but there is a small gap in the bottom (i can see the tab bar in the background), its almost in the size of a status bar on the top. i think the view is not loading the correct origin. do you have any idea why its so ?
  • shinto Joseph
    shinto Joseph over 14 years
    Hi, I tried and its loading the view [window addSubview:tabBar.view]; [window makeKeyAndVisible]; [self.tabBar presentModalViewController:controller animated:NO]; I put a button in the SplashScreen to dismiss and the code i used to dismiss the view is UIView *currentView = self.view; [currentView removeFromSuperview]; it will dismiss the splash screen, but not showing the TabBar. could you please help me to solve this ?
  • Dana
    Dana over 14 years
    Oh yeah, I think that happened to me too. I'm trying to remember what I did...in your controller in the nib, have you set it to be 320x480 in seize and set Status Bar, Top Bar and Bottom Bar all to None?
  • Frank Schmitt
    Frank Schmitt over 14 years
    What you want to do is call [self.parentViewController dismissModalViewControllerAnimated:YES] (or NO).
  • mr-sk
    mr-sk over 14 years
    Hmm..I don't know - do you have something on your spring/struts set that could be making the view load off a little?
  • Adam Woś
    Adam Woś over 14 years
    Second that! Do not use splash screens, they're frowned upon by the iPhone reviewers.
  • shinto Joseph
    shinto Joseph over 14 years
    size of the view is 320x460 and status bar is on
  • Andy
    Andy about 14 years
    This is hogwash, IMO (Apple's reasoning, that is). They say "...a launch image is to improve user experience..." What's a worse user experience than staring at an empty table waiting for your data to load? The old adage about "time on hold appears to last 3x longer than actual time spent on hold" applies here, too: I wouldn't notice the time spent waiting if it wasn't so blatantly obvious that I was waiting on that empty table to fill with my data. I'd much rather that happen in the background while the developer's logo fades in and out (or something). Give me something to look at.
  • George
    George about 12 years
    seems a good answer. I know the present modal view controller is really the best but if you want to keep it simple , this is just as good. One problem though, you cannot get rotation events in the app delegate so you can't use it for app with autorotate.
  • Julian F. Weinert
    Julian F. Weinert over 8 years
    By the way: In performSelector:withObjectAfterDelay: you CAN NOT PASS BOOLS! The method says it: withObject. YES and NO are no objects, but scalar BOOL values. And even if you pass @YES or @NO (their respective object counterpart) they won't be unpacked to the scalar BOOL, so you'll end up with an expression of if (animated != nil) wich will be always true.