今天就和大家分享一下关于IOSAPP开机动画的问题,因为在ios的程序中启动图是一张静止的图片,所以要做开机动画必须要在appDelegate里面进行,将动画代码写在didFinishLaunchingWithOptions的方法里面,代码如下:
注意:在执行动画的时候必须先选择主控制器,这样动画才能进行,小编在写完程序的时候,曾经把下面红色代码删除,造成启动时动画丢失的情况,请广大程序猿注意!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor whiteColor];
self.splashView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.splashView.userInteractionEnabled = YES;
self.splashView.image = [UIImage imageNamed:@"new_feature_0"];
[self.window addSubview:self.splashView];
[self.window bringSubviewToFront:self.splashView];
[self performSelector:@selector(scale_1) withObject:nil afterDelay:0.0f];
[self performSelector:@selector(showWord) withObject:nil afterDelay:0.0f];
[UIView animateWithDuration:0 delay:4 options:UIViewAnimationOptionAllowUserInteraction animations:^{
HXTabBarController *tabBarCV = [HXTabBarController new];
[tabBarCV.tabBar removeFromSuperview];
self.window.rootViewController = tabBarCV;
} completion:^(BOOL finished) {
//设置根控制器
self.key = @"CFBundleShortVersionString";
//上一次的使用版本(存储在沙盒中的版本号号)
NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:self.key];
//当前软件的版本号(conginfo.plist中获得)
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[self.key];
//版本号相同,这次打开和上次打开的是同一个版本
if ([currentVersion isEqualToString:lastVersion]) {
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
HXTabBarController *tabBarC = [story instantiateInitialViewController];
self.tabBarController = tabBarC;
self.window.rootViewController = tabBarC;
} else {
//这次打开的版本和上次不一样,显示新特性
self.window.rootViewController = [[HXNewFeatureController alloc] init];
//将当前的版本号存近沙盒
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:self.key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
[self.splashView removeFromSuperview];
}];
return YES;
}
-(void)scale_1
{
UIImageView *dragon = [[UIImageView alloc]init];
dragon.image = [UIImage imageNamed:@"dragon"];
dragon.width = 1;
dragon.height = 1;
[self.splashView addSubview:dragon];
[self setDragon:dragon];
}
-(void)setDragon:(UIImageView *)nowView
{
[UIView animateWithDuration:2 animations:^{
nowView.width = 173;
nowView.height = 227;
nowView.centerX = self.splashView.centerX;
nowView.centerY = self.splashView.height * 0.35;
}completion:^(BOOL finished){
}];
}
-(void)showWord
{
UIImageView *honorable = [[UIImageView alloc]init];
honorable.image = [UIImage imageNamed:@"honorable"];
honorable.width = 250;
honorable.height = 90;
honorable.centerX = self.splashView.centerX;
honorable.y = self.splashView.height - 200;
[self.splashView addSubview:honorable];
honorable.alpha = 0.0;
[UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
animations:^{
honorable.alpha = 1.0;
}completion:^(BOOL finished){
// 完成后执行code
[NSThread sleepForTimeInterval:2.0f];
}];
}