-
-
Save nbrew/6393764 to your computer and use it in GitHub Desktop.
iOS - Fade from the splash screen to your initial view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on and inspired by https://gist.github.com/1026439 and https://gist.github.com/3798781 | |
// | |
// MIT license. Use however you'd like. | |
// | |
// first, define our macro for delaying our transition: | |
#define PKWaitDelay(dly, block) dispatch_after(dispatch_time(DISPATCH_TIME_NOW,dly*100000),dispatch_get_main_queue(), ^{ block }) | |
// then, inside your AppDelegate.m in didFinishLaunchingWithOptions: | |
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.frame]; | |
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) | |
{ | |
switch ( [[UIApplication sharedApplication] statusBarOrientation] ) | |
{ | |
case UIInterfaceOrientationLandscapeLeft: | |
case UIInterfaceOrientationLandscapeRight: | |
if ( [UIScreen mainScreen].scale == 2 ) { imageView.image = [UIImage imageNamed:@"Default-Landscape@2x~ipad.png"]; } | |
else { imageView.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"]; } | |
[imageView setFrame: CGRectMake(0, 0, 1024, 748) ]; | |
break; | |
case UIInterfaceOrientationPortrait: | |
case UIInterfaceOrientationPortraitUpsideDown: | |
if ( [UIScreen mainScreen].scale == 2 ) { imageView.image = [UIImage imageNamed:@"Default-Portrait@2x~ipad.png"]; } | |
else { imageView.image = [UIImage imageNamed:@"Default-Portrait~ipad.png"]; } | |
[imageView setFrame: CGRectMake(0, 0, 768, 1004) ]; | |
break; | |
} | |
} | |
else | |
{ | |
// we're an iPhone or iPod touch. No rotation for you. | |
if ( [UIScreen mainScreen].scale == 2 ) | |
{ | |
// are we a 3.5in? or a 4? | |
if ([UIScreen mainScreen].bounds.size.height == 568.0f) | |
{ | |
// 4 inch iPhone 5 | |
imageView.image = [UIImage imageNamed:@"[email protected]"]; | |
[imageView setFrame: CGRectMake(0, 0, 320, 548) ]; | |
} | |
else | |
{ | |
imageView.image = [UIImage imageNamed:@"[email protected]"]; | |
[imageView setFrame: CGRectMake(0, 0, 320, 460) ]; | |
} | |
} | |
else | |
{ | |
imageView.image = [UIImage imageNamed:@"Default.png"]; | |
[imageView setFrame: CGRectMake(0, 0, 320, 460) ]; | |
} | |
} | |
[self.window.rootViewController.view addSubview:imageView]; | |
[self.window.rootViewController.view bringSubviewToFront:imageView]; | |
PKWaitDelay(2,{ | |
[UIView transitionWithView:self.window | |
duration:1.00f | |
options:(enum UIViewAnimationOptions)UIViewAnimationCurveEaseInOut | |
animations:^(void){ | |
imageView.alpha = 0.0f; | |
} | |
completion:^(BOOL finished){ | |
[imageView removeFromSuperview]; | |
}];} | |
); | |
[self.window makeKeyAndVisible]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment