美文网首页weex
iOS-Weex-Gif图片显示

iOS-Weex-Gif图片显示

作者: hhao | 来源:发表于2019-08-01 13:55 被阅读0次

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

pod 'SDWebImage','4.4.2'

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

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

第三步:实现WXImgLoaderDefaultImpl类

WXImgLoaderDefaultImpl.h文件

#import <Foundation/Foundation.h>
#import <WeexSDK/WeexSDK.h>

@interface WXImgLoaderDefaultImpl : NSObject<WXImgLoaderProtocol, WXModuleProtocol>
@end


#import "WXImgLoaderDefaultImpl.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/UIImage+GIF.h>

WXImgLoaderDefaultImpl.m文件

@implementation WXImgLoaderDefaultImpl

- (id<WXImageOperationProtocol>)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)userInfo completed:(void(^)(UIImage *image,  NSError *error, BOOL finished))completedBlock
{
    return (id<WXImageOperationProtocol>)[[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图片显示

    第一步:在项目中即成SDWebImage库 第二步:在初始化WXSDKEngine时注册图片库 第三步:实现WXI...

  • 图片显示

    //标签按钮 @property(nonatomic,strong)UILabel *titleLabel; //...

  • 显示图片

    springboot部署的时候一般打成jar包,那么在想象一下图片下载,并展示的情况。下载的图片必须要服务器中间件...

  • 显示图片

    import pygame

  • 21_显示YUV图片&视频

    一、显示YUV图片 显示 YUV 图片和显示 BMP 图片的大致流程是一样的。显示 BMP 图片我们可以直接获取到...

  • UI基础控件- UIImageView

    UIImageView 功能:显示图片 常见属性:image:显示的图片animationImages:显示的动画...

  • YYImage/YYWebImage

    YYImage YYKit的图像框架 显示普通动画类型图片 显示帧动画 显示精灵图片精灵图片? 判断图片格式 YY...

  • July 27-day12-Python初识pygame

    显示字体 显示结果: 显示图片 显示结果: 显示图形 显示结果:

  • 【GeekBand】UIImage显示图片

    UIImage 通过属性显示assets中的图片 通过代码显示图片 显示图片最直接的方式就是使用Image Vie...

  • Day_10 异常与pygame

    异常捕获 pygame操作流程 pygame显示文字 pygame显示图片与图片操作 pygame基本显示

网友评论

    本文标题:iOS-Weex-Gif图片显示

    本文链接:https://www.haomeiwen.com/subject/xjmqdctx.html