Skip to content

Instantly share code, notes, and snippets.

@benvium
Created September 28, 2012 09:05
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save benvium/3798781 to your computer and use it in GitHub Desktop.
Save benvium/3798781 to your computer and use it in GitHub Desktop.
iOS: Fade from the splash screen to your initial view. Works on iPhone 5 (and 4,3). Add a UIImageView property called splashView.
- (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:@"Default-568h@2x.png"];
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];
}
@montj2
Copy link

montj2 commented Dec 9, 2013

I have this in my App Delegate and - (void)startupAnimationDone:finished:context: is called, but the duration makes no difference. I don't see a delayed fade.

@haojianzong
Copy link

Don't work for me as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment