方法一:
官方SDK最简单的方法
最简单的方法就是做一个全屏的欢迎页的图片,把它命名为Default.png,然后放在Xcode工程的Resource里面。 执行就可以看到你的这个默认图像在程序完全加载之前显示在屏幕上。
但是这个方法有个问题,如果你的程序很快载入了,这个图片会立刻消失,导致还没有看清楚图片上的内容。 而且有些内容虽然程序已经载入了,但是有些程序需要的资源是要从服务器上加载的,所以直接进入程序,用户还是无法使用这个应用。
方法二:
1. 将你需要的splash界面的图片,存成Default.png
2. 在XXXAppDelegate.m程序中,插入如下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; //开始; [NSThread sleepForTimeInterval:3.0]; //结束; // Override point for customization after application launch. self.window.backgroundColor=[UIColor redColor];//加个背景红色 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; } else { self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; } self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
[NSThread sleepForTimeInterval:3.0]是splash页面停留3秒后消失。
方法三:
找个带有动画效果,原理:
添加一张和Default.png一样的图片,对这个图片进行动画,从而实现Default动画的渐变消失的效果。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. //self.window.backgroundColor=[UIColor redColor];//加个背景红色 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; } else { self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; } self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; //开始 UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; splashView.image = [UIImage imageNamed:@"Default.png"]; [self.window addSubview:splashView]; [self.window bringSubviewToFront:splashView]; //放到最顶层; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3.0]; [UIView setAnimationTransition:UIViewAnimationTransitionNone forView: self.window cache:YES]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; splashView.alpha = 0.0; splashView.frame = CGRectMake(-60, -85, 440, 635); [UIView commitAnimations]; [splashView release]; //结束; return YES; }
方法四:
ps:
让Splash启动画面全屏:
1.在<APP>-info.list文件中,加上“Status bar is initially hidden”选项,选择yes
2在程序里面添加 [[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];