如题,我们项目在开屏广告中添加了GIF动画,由于启动过程中广告加载的同时也加载了首页,由于首页加载存在耗时操作,导致播放GIF的时候开始会卡顿几下
原来的写法:(卡顿)FLAnimatedImage渲染
/// 需要导入头文件
#import <FLAnimatedImage/FLAnimatedImage.h>
FLAnimatedImageView *gifView = [[FLAnimatedImageView alloc] init];
NSURL *imUurl = [[NSBundle mainBundle] URLForResource:@"name" withExtension:@"gif"];
NSData *data = [NSData dataWithContentsOfURL:imUurl];
gifView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:data];
更改写法: (解决卡顿问题) 生成 UIImage 交给系统渲染
/// 需要导入头文件
#import <SDWebImage/UIImage+GIF.h>
#import <FLAnimatedImage/FLAnimatedImage.h>
FLAnimatedImageView *gifView = [[FLAnimatedImageView alloc] init];
NSURL *imUurl = [[NSBundle mainBundle] URLForResource:@"name" withExtension:@"gif"];
NSData *data = [NSData dataWithContentsOfURL:imUurl];
UIImage *image = [UIImage sd_animatedGIFWithData:data];
gifView.image = image;
如上:解决了GIF卡顿问题