Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@montj2 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

This comment has been minimized.

Copy link

@haojianzong haojianzong commented May 29, 2015

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