1

So I know Default.png can be used for a splash screen in an iPhone app but I find it looks unprofessional because there is no animation once the application has completed loading.

So I am trying to add a splash screen that will fade out and then go to the last previous view.

Most of the examples on the internet tend to be based around the old way of doing things with addSubview. How would I go about adding this to my storyboard application.

Current Code ( timings are wrong because I wasn't sure it was working originally )

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    splashView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default2.png"]];
    splashView.frame = CGRectMake(0, 0, 324, 480);
    [_window addSubview:splashView];
    [_window bringSubviewToFront:splashView];
    [_window makeKeyAndVisible];

    [self performSelector:@selector(removeSplash) withObject:nil afterDelay:1500.2];
    return YES;
}

-(void)removeSplash;
{
    [UIView animateWithDuration:1.0 animations:^{self.splashView.alpha = 0.0;} completion:^(BOOL finished){ [splashView removeFromSuperview]; }];
    [splashScreen release];
}
mintuz
  • 735
  • 1
  • 18
  • 40
  • +1 because I think there's a big gap in widely understood and accepted patterns for splash screens and first time use experiences. This was a gap before storyboards. Storyboards is a big improvement for most of the app, but for the startup and first time run, I think they have only confused matters further. – danh Jun 09 '12 at 17:58
  • 1
    The splash screen is supposed to look like the first screen of your application, but empty, then the transition is pretty much flawless when it finished loading. I **STRONGLY** disagree when you say that it looks unprofessional (unless you are doing it wrong, of course). Also, it's not the _old_ way of doing it, it's just _another_ way, the fact that Storyboards exist doesn't make code obsolete. – EmilioPelaez Jun 09 '12 at 20:53

2 Answers2

3

Besides Guntis Treulands's answer I have another way to do this without move the animation code out of the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.

Just add your splashView directly to _window.rootViewController.view.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIImage *splashImage = [UIImage autoAdjustImageNamed:@"Default.png"];
    UIImageView *splashImageView = [[UIImageView alloc] initWithImage:splashImage];
    [self.window.rootViewController.view addSubview:splashImageView];
    [self.window.rootViewController.view bringSubviewToFront:splashImageView];
    [UIView animateWithDuration:1.5f
                          delay:2.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         splashImageView.alpha = .0f;
                         CGFloat x = -60.0f;
                         CGFloat y = -120.0f;
                         splashImageView.frame = CGRectMake(x,
                                                            y,
                                                            splashImageView.frame.size.width-2*x,
                                                            splashImageView.frame.size.height-2*y);
                     } completion:^(BOOL finished){
                         if (finished) {
                             [splashImageView removeFromSuperview];
                         }
                     }];

    return YES;
}
Community
  • 1
  • 1
sunkehappy
  • 8,970
  • 5
  • 44
  • 65
1

In your case I would still add it as a subview, but always keep it as a top subview on window. When it's alpha == 0 it will stop receiving touches. So.. no reason to release it every time you want to fade it out.

In my case - client wanted to see splash screen every time application is maximized or opened so I also did this:

- (void)applicationDidEnterBackground:(UIApplication *)application 
{
    extraSplashScreen.alpha = 1;  //when it goes in background - set splash screen visible.
}

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    [self fadeOutSplash]; //initiate fade out.
}

My fadeOutSplash function looks like this (just in case):

- (void)fadeOutSplash
{
    [UIView beginAnimations:nil context:NULL];  

    [UIView setAnimationDelegate:self];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];   

    [UIView setAnimationDuration:0.3];

    [UIView setAnimationDelay:0.5];

    extraSplashScreen.alpha = 0;

    [UIView commitAnimations];
}

Hope that helps.

Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72