iOS 启动页怎么显示GIF图

不管是怎么样加载动态图 都无法跳过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;

        }];

    }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容