-
(void)setUpLaunchScreen{
NSURL *fileUrl;
if (screen_width==480) {// 屏幕的高度为480
fileUrl = [[NSBundle mainBundle] URLForResource:@"startup1" withExtension:@"gif"]; // 加载GIF图片
}else if(screen_width==568) {// 屏幕的高度为568
//5 5s 0.853333 0.851574
fileUrl = [[NSBundle mainBundle] URLForResource:@"startup2" withExtension:@"gif"]; // 加载GIF图片}else if(screen_width==667){// 屏幕的高度为667
//6 6s 7 1.000000 1.000000
fileUrl = [[NSBundle mainBundle] URLForResource:@"startup3" withExtension:@"gif"]; // 加载GIF图片
}else if(screen_width==736){// 屏幕的高度为736
//6p 6sp 7p
fileUrl = [[NSBundle mainBundle] URLForResource:@"startup4" withExtension:@"gif"]; // 加载GIF图片
}else if(screen_width==812){// 屏幕的高度为812 375.000000 812.000000
// x
fileUrl = [[NSBundle mainBundle] URLForResource:@"startup5" 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.launchImageView = [[UIImageView alloc]initWithFrame:self.window.bounds];
NSLog(@"宽高为%lf %lf",self.window.bounds.size.width,self.window.bounds.size.height);
self.launchImageView.userInteractionEnabled = YES;self.launchImageView.animationImages = frames; // 将图片数组加入UIImageView动画数组中
self.launchImageView.animationDuration = 0.7; // 每次动画时长
[self.launchImageView startAnimating]; // 开启动画,此处没有调用播放次数接口,UIImageView默认播放次数为无限次,故这里不做处理[[UIApplication sharedApplication].keyWindow addSubview:self.launchImageView];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:self.launchImageView];//5秒后自动关闭
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self yourButtonClick];
});
}
-
(void)yourButtonClick {
// 移动自定义启动图
if (self.launchImageView) {
[UIView animateWithDuration:0.3 animations:^{
self.launchImageView.alpha = 0;
} completion:^(BOOL finished) {
[self.launchImageView removeFromSuperview];
self.launchImageView = nil;
}];
}
}
网友评论