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