不管是怎么样加载动态图 都无法跳过LaunchImage或者LaunchScreen.storyboard 所以想一加载出来就是动态是实现不了的 稍微会延迟一下 效果也还可以
方法有好几种 主要思路就是LaunchImage放GIF的第一张图片 用代码再加载gif图
/添加启动图
- (void)setUpLaunchScreen{
NSURL *fileUrl;
if (SCREENH_HEIGHT==480) {// 屏幕的高度为480
fileUrl = [[NSBundle mainBundle] URLForResource:@"启动页" withExtension:@"gif"]; // 加载GIF图片
}else if(SCREENH_HEIGHT==568) {// 屏幕的高度为568
//5 5s 0.853333 0.851574
fileUrl = [[NSBundle mainBundle] URLForResource:@"启动页1" withExtension:@"gif"]; // 加载GIF图片
}else if(SCREENH_HEIGHT==667){// 屏幕的高度为667
//6 6s 7 1.000000 1.000000
fileUrl = [[NSBundle mainBundle] URLForResource:@"启动页2 withExtension:@"gif"]; // 加载GIF图片
}else if(SCREENH_HEIGHT==736){// 屏幕的高度为736
//6p 6sp 7p
fileUrl = [[NSBundle mainBundle] URLForResource:@"启动页3" withExtension:@"gif"]; // 加载GIF图片
}else if(SCREENH_HEIGHT==812){// 屏幕的高度为812 375.000000 812.000000
// x
fileUrl = [[NSBundle mainBundle] URLForResource:@"启动页4" withExtension:@"gif"]; // 加载GIF图片
}else{
}
CGImageSourceRef gifSource = CGImageSourceCreateWithURL((CFURLRef) fileUrl, NULL); //将GIF图片转换成对应的图片源
size_t frameCout = CGImageSourceGetCount(gifSource); // 获取其中图片源个数,即由多少帧图片组成
NSMutableArray *frames = [[NSMutableArray alloc] init]; // 定义数组存储拆分出来的图片
for (size_t i = 0; i < frameCout; i++) {
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(gifSource, i, NULL); // 从GIF图片中取出源图片
UIImage *imageName = [UIImage imageWithCGImage:imageRef]; // 将图片源转换成UIimageView能使用的图片源
[frames addObject:imageName]; // 将图片加入数组中
CGImageRelease(imageRef);
}
self.customLaunchImageView = [[UIImageView alloc]initWithFrame:self.window.bounds];
NSLog(@"宽高为%lf %lf",self.window.bounds.size.width,self.window.bounds.size.height);
self.customLaunchImageView.userInteractionEnabled = YES;
self.customLaunchImageView.animationImages = frames; // 将图片数组加入UIImageView动画数组中
self.customLaunchImageView.animationDuration = 1; // 每次动画时长
[self.customLaunchImageView startAnimating]; // 开启动画,
[[UIApplication sharedApplication].keyWindow addSubview:self.customLaunchImageView];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:self.customLaunchImageView];
//5秒后自动关闭
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self yourButtonClick];
});
}
- (void)yourButtonClick {
// 移动自定义启动图
if (self.customLaunchImageView) {
[UIView animateWithDuration:0.3 animations:^{
self.customLaunchImageView.alpha = 0;
} completion:^(BOOL finished) {
[self.customLaunchImageView removeFromSuperview];
self.customLaunchImageView = nil;
}];
}
}