iOS SDWebImage 加载GIF图片没效果

2018-09-29  本文已影响1081人  iOS开发小学生

//加载本地GIF图片

 NSString *filepath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"abc.gif" ofType:nil];
    NSData *imagedata = [NSData dataWithContentsOfFile:filepath];
    UIImageView *loadingimage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, (BXScreenW-30)/2, BXScreenH/2-20)];
    loadingimage.image= [UIImage sd_animatedGIFWithData:imagedata];
    [self.view addSubview:loadingimage];

//加载网络GIF图片 (SDWebImage 4.0 之前)

UIImageView *loadingimagetwo = [[UIImageView alloc] initWithFrame:CGRectMake((BXScreenW-30)/2+20,10, (BXScreenW-30)/2, BXScreenH/2-20)];
    [loadingimagetwo sd_setImageWithURL:[NSURL URLWithString:@"http://img1.imgtn.bdimg.com/it/u=473895314,616407725&fm=206&gp=0.jpg"]];
    [self.view addSubview:loadingimagetwo];

//加载网络GIF图片(SDWebImage 4.0 之后)

FLAnimatedImage *image=  [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img1.imgtn.bdimg.com/it/u=473895314,616407725&fm=206&gp=0.jpg"]]];
    FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
    imageView.animatedImage = image;
    imageView.frame = CGRectMake(10,BXScreenH/2 , self.view.frame.size.width-20, BXScreenH/2-100);
    [self.view addSubview:imageView];

总结:1.新版本SDWebImage不再支持原先的方式了,用他们之前弄了一个单独的类FLAnimatedImage来播放gif。
2.参考GitHub https://github.com/Flipboard/FLAnimatedImage
3.pod 'FLAnimatedImage', '~> 1.0' #import "FLAnimatedImage.h"
附加亲测效果图

效果图.gif
上一篇下一篇

猜你喜欢

热点阅读