iOS开发-SDWebImage4.0之后加载gif不显示的解决方案(FLAnimatedImageView FLAnimatedImage)

之前的使用方法

    UIImageView *imgView = [UIImageView new];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    imgView.frame = CGRectMake(0, 0, 100, 30);

    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"going" ofType:@"gif"];
    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
    imgView.backgroundColor = [UIColor clearColor];
    imgView.image = [UIImage sd_animatedGIFWithData:imageData];
    [self addSubview:imgView];

SDWebImage4.0之后使用以上的方法显示gif图,会显示不出来。
访问SDWebImage的github网址

SDWebImage github网址

Animated Images (GIF) support

  • Starting with the 4.0 version, we rely on FLAnimatedImage to take care of our animated images.
  • If you use cocoapods, add pod 'SDWebImage/GIF' to your podfile.
  • To use it, simply make sure you use FLAnimatedImageView instead of UIImageView.
  • Note: there is a backwards compatible feature, so if you are still trying to load a GIF into a UIImageView, it will only show the 1st frame as a static image.
  • Important: FLAnimatedImage only works on the iOS platform. For OS X, use NSImageView with animates set to YES to show the entire animated images and NO to only show the 1st frame. For all the other platforms (tvOS, watchOS) we will fallback to the backwards compatibility feature described above

使用下面的新方法就可以正常显示gif

    FLAnimatedImageView *imgView = [FLAnimatedImageView new];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    imgView.frame = CGRectMake(0, 0, 100, 30);
    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"going" ofType:@"gif"];
    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
    imgView.backgroundColor = [UIColor clearColor];
    imgView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
    [self addSubview:imgView];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值