SDWebimage加载GIF图片不动
2020-05-14 本文已影响0人
追风少年_fc4e
SDWebimage 在4.0版本之前,调用如下的方法可以直接展示GIF的图片
- (void)sd_setImageWithURL:(nullable NSURL *)url
placeholderImage:(nullable UIImage *)placeholder
options:(SDWebImageOptions)options
completed:(nullable SDExternalCompletionBlock)completedBlock;
但是4.0版本之后就不行了,因为SDWebimage新加入了FLAnimatedImageView这个类
直接用FLAnimatedImageView创建一个imageview 然后再调用之前的方法就可以了
具体的实现步骤:
pod导入下面的库
pod 'SDWebImage/GIF'
创建imageView
.h文件
//倒入头文件
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
@interface LSLaunchView : UIView
@property (nonatomic, weak) FLAnimatedImageView *adImageView;
@end
.m文件
- (void)addAdImageView
{
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
[self addSubview:imageView];
//下面方法二选一 根据自己的需求
//带占位图的方法
NSURL *url = [NSURL URLWithString:(NSString *)object.strIcon];
[imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon_placeholder"]];
//带block的方法
[_launchView.adImageView sd_setImageWithURL:url placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//
NSLog(@"实现一些方法");
} ];
}
加载本地GIF
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"图片名称.gif" ofType:nil];
NSData *imageData = [NSData dataWithContentsOfFile: filePath];
UIImageView *adImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, (BXScreenW-30)/2, BXScreenH/2-20)];
adImage.image = [UIImage sd_animatedGIFWithData: imageData];
[self.view addSubview: adImage];
备注:
还有一种方式 就是将pod 库的SDWebImage回退到4.0之前的版本
pod 'SDWebImage','3.8.2'