进度条动画:http://blog.csdn.net/jwzbskywz/article/details/7703042
首先,iOS 的 launch images 只能是静态图片
启动『动画』应该实际上是两部分,那张静态 launch image 作为起点,App 实际启动后播放完整的动画。
iOS软件开发中,通常在软件启动时需要创建一个闪屏显示欢迎信息,在显示闪屏的同时可以让程序在后台进行一些初始化工作,例如,检查网络连接、读取系统 设置等,等初始化工作完成以后再显示程序主界面,这里我们使用定时器来制作闪屏,在定时器到期以后,移除闪屏,显示程序主界面,并使用UIView的动画 方法使闪屏平滑过渡到主界面显示.
这里主要用到了定时器:
//NSTimer其实是将一个监听加入的系统的RunLoop中去,当系统runloop到如何timer条件的循环时,
//会调用timer一次,当timer执行完,也就是回调函数执行之后,timer会再一次的将自己加入到runloop中去继续监听
1 | _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) |
2 | userInfo:nil repeats:NO];<span> </span> |
代码:
01 | #import "StartupScreenViewController.h" |
02 | @interface StartupScreenViewController () |
06 | @implementation StartupScreenViewController |
07 | @synthesize timer = _timer; |
08 | @synthesize splashImageView = _splashImageView; |
09 | @synthesize mainViewController = mainviewController; |
11 | CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; |
12 | UIView *view = [[UIView alloc] initWithFrame:appFrame]; |
13 | view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; |
17 | _splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @ "splash.png" ]]; |
18 | _splashImageView.frame = CGRectMake(0, 0, 320, 480); |
19 | [self.view addSubview:_splashImageView]; |
20 | _viewController = [[MainViewController alloc] init]; |
21 | _viewController.view.alpha = 0.0; |
22 | [self.view addSubview:viewController.view]; |
24 | _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; |
29 | [UIView beginAnimations:nil context:nil]; |
30 | [UIView setAnimationDuration:0.75]; |
31 | [UIView setAnimationDelegate:self]; |
32 | [UIView setAnimationDidStopSelector:@selector(finishedFading)]; |
33 | self.view.alpha = 0.0; |
34 | [UIView commitAnimations]; |
37 | - ( void ) finishedFading{ |
38 | [UIView beginAnimations:nil context:nil]; |
39 | [UIView setAnimationDuration:0.75]; |
40 | self.view.alpha = 1.0; |
41 | viewController.view.alpha = 1.0; |
42 | [UIView commitAnimations]; |
43 | [_splashImageView removeFromSuperview]; |
47 | - ( BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
49 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; |
51 | self.viewController = [[[ViewController alloc] initWithNibName:@ "ViewController" bundle:nil] autorelease]; |
52 | self.window.rootViewController = self.viewController; |
53 | [self.window makeKeyAndVisible]; |
55 | UIImageView *splashScreen = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease]; |
56 | splashScreen.image = [UIImage imageNamed:@ "Default" ]; |
57 | [self.window addSubview:splashScreen]; |
59 | [UIView animateWithDuration:1.0 animations:^{ |
60 | CATransform3D transform = CATransform3DMakeScale(1.5, 1.5, 1.0); |
61 | splashScreen.layer.transform = transform; |
62 | splashScreen.alpha = 0.0; |
63 | } completion:^( BOOL finished) { |
64 | [splashScreen removeFromSuperview]; |