Skip to content

Instantly share code, notes, and snippets.

@benvium
Created September 28, 2012 09:05
Show Gist options
  • Select an option

  • Save benvium/3798781 to your computer and use it in GitHub Desktop.

Select an option

Save benvium/3798781 to your computer and use it in GitHub Desktop.

Revisions

  1. benvium created this gist Sep 28, 2012.
    38 changes: 38 additions & 0 deletions FadeSplash.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //.. do other setup

    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;

    // Transition neatly from splash screen

    // Very odd, on iPhone 5 you need to position the splash screen differently..
    UIImage* myImage;
    if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f) {
    myImage = [UIImage imageNamed:@"[email protected]"];
    self.splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,20, 320, screenHeight-20)];
    } else {
    myImage = [UIImage imageNamed:@"Default.png"];
    self.splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, screenHeight)];
    }

    self.splashView.image = myImage;

    [self.window addSubview:self.splashView];
    [self.window bringSubviewToFront:self.splashView];

    // setup the animation of the splash screen
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    self.splashView.alpha = 0.0;
    [UIView commitAnimations];
    }

    // Called when the animation that hides Default.png finishes, use it to clean up.
    - (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [self.splashView removeFromSuperview];
    }