# SDWebImage4.x加载GIF图片的方法

**URL:** https://www.shiqidu.com/t/topic/549
**Category:** 开发调优
**Tags:** C-C-Obj-C
**Created:** [2019 年2 月 15 日 00:20 UTC](https://www.shiqidu.com/t/topic/549 "2019-02-15T00:20:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### 作者： ![Eureka](https://www.shiqidu.com/user_avatar/www.shiqidu.com/eureka/32/5_2.png) [@Eureka](https://www.shiqidu.com/u/Eureka)
#### 发布日期： [2019 年2 月 15 日 00:20 UTC](https://www.shiqidu.com/t/topic/549/1 "2019-02-15T00:20:44Z")

</div>

首先需要安装下面的两个包

```bash
pod 'SDWebImage/GIF'
pod 'FLAnimatedImage'

```

然后代码中引入这两个头文件

```oc
#import <FLAnimatedImageView.h>
#import <FLAnimatedImageView+WebCache.h>

```

加载gif图片需要使用FLAnimatedImageView

```oc
// imageview
NSString *originalImagePath = [WEBSITE_PREFIX stringByAppendingPathComponent:self.imageItem[@"original"]];
UIImageView *imageView = [[UIImageView alloc] init];
if ([originalImagePath hasSuffix:@".gif"]) {
    imageView = [[FLAnimatedImageView alloc] init];
}
self.imageView = imageView;

// SQDLog(@"%@", originalImagePath);
[imageView sd_setImageWithURL:[NSURL URLWithString:originalImagePath] completed:^(UIImage *_Nullable image, NSError *_Nullable error, SDImageCacheType cacheType, NSURL *_Nullable imageURL) {
    if (!image) {
        [SVProgressHUD showErrorWithStatus:@"图片下载失败"];
        return;
    }
    self.saveBtn.enabled = YES;
}];

```
