iOS启动动画效果实现
原理
在window上加一个UIImageView它的图片和启动图的图片一样,然后再调整动画
运行展示
demo百度云连接:http://pan.baidu.com/s/1c0QcYu0
more:网上看了一个哥们的封装的还不错,分析下代码:
宏定义
#define iphone4x_3_5 ([UIScreen mainScreen].bounds.size.height==480.0f) #define iphone5x_4_0 ([UIScreen mainScreen].bounds.size.height==568.0f) #define iphone6_4_7 ([UIScreen mainScreen].bounds.size.height==667.0f) #define iphone6Plus_5_5 ([UIScreen mainScreen].bounds.size.height==736.0f || [UIScreen mainScreen].bounds.size.height==414.0f)
获取启动图片,你创建的图片资源文件里面的
/** * 获取启动图片 */ +(UIImage *)launchImage{ NSString *imageName=@"LaunchImage-700"; if(iphone5x_4_0) imageName=@"LaunchImage-700-568h"; if(iphone6_4_7) imageName = @"LaunchImage-800-667h"; if(iphone6Plus_5_5) imageName = @"LaunchImage-800-Portrait-736h"; UIImage *image = [UIImage imageNamed:imageName]; NSAssert(image != nil, @"Charlin Feng提示您:请添加启动图片!"); return image; }
设置动画根据需要合一随意变的(这里它就是添加到控制器上面的)
+(void)animWithWindow:(UIWindow *)window image:(UIImage *)image{ UIImageView *imageV = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]; imageV.image = image==nil?[self launchImage]:image; [window.rootViewController.view addSubview:imageV]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [UIView animateWithDuration:1.5 animations:^{ [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; imageV.transform=CGAffineTransformMakeScale(1.5, 1.5); imageV.alpha = 0; } completion:^(BOOL finished) { [imageV removeFromSuperview]; }]; }); }
调用(ok)
[WJLaunchImage animWithWindow:self.window image:nil];