1、首先需要在podfile里面安装依赖
pod 'SDWebImage'
pod 'SDWebImage/GIF'
2、代码如下:
// 引入头文件
#import "FLAnimatedImageView+WebCache.h"
// 显示GIF图片
FLAnimatedImageView *bannerImageView = [FLAnimatedImageView new];
bannerImageView.contentMode = UIViewContentModeScaleAspectFit;
bannerImageView.frame = CGRectMake(0, 0, kScreenWidth, headerViewHeight);
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"MECoinbanner" ofType:@"gif"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
bannerImageView.backgroundColor = [UIColor clearColor];
bannerImageView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
[_tableHeaderView addSubview:bannerImageView];