iOS-Weex-Gif图片显示

第一步:在项目中即成SDWebImage库

pod 'SDWebImage','4.4.2'

第二步:在初始化WXSDKEngine时注册图片库

[WXSDKEngine registerHandler:[WXImgLoaderDefaultImpl new] withProtocol:@protocol(WXImgLoaderProtocol)];

第三步:实现WXImgLoaderDefaultImpl类

WXImgLoaderDefaultImpl.h文件

#import 
#import 

@interface WXImgLoaderDefaultImpl : NSObject
@end


#import "WXImgLoaderDefaultImpl.h"
#import 
#import 

WXImgLoaderDefaultImpl.m文件

@implementation WXImgLoaderDefaultImpl

- (id)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)userInfo completed:(void(^)(UIImage *image,  NSError *error, BOOL finished))completedBlock
{
    return (id)[[SDWebImageManager sharedManager].imageDownloader downloadImageWithURL:[NSURL URLWithString:url] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
        
    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
        if (completedBlock) {
            // 关键点
            if ([url hasSuffix:@"gif"]) {
                UIImage *images = [UIImage sd_animatedGIFWithData:data];
                completedBlock(images, error, finished);
            }else{
                completedBlock(image, error, finished);
            }
        }
        
    }];
}

你可能感兴趣的:(iOS-Weex-Gif图片显示)