添加启动动画 (自制ios启动动画)

进度条动画: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 ()
03  
04 @end
05  
06 @implementation StartupScreenViewController
07 @synthesize timer = _timer;
08 @synthesize splashImageView = _splashImageView;
09 @synthesize   mainViewController = mainviewController; //主界面
10  -(void)loadView{
11     CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
12     UIView *view = [[UIView alloc] initWithFrame:appFrame];
13     view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
14     self.view = view;
15     [view release];
16      
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];
23  
24  _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO];
25  
26 }
27  
28 - (void)fadeScreen{
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];
35 }
36  
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];
44 }
45  
46 例子2:
47 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
48 {
49     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
50     // Override point for customization after application launch.
51     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
52     self.window.rootViewController = self.viewController;
53     [self.window makeKeyAndVisible];
54      
55     UIImageView *splashScreen = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];
56     splashScreen.image = [UIImage imageNamed:@"Default"];
57     [self.window addSubview:splashScreen];
58      
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];
65     }];
66      
67     return YES;
68
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值