//加載本地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];
//加載網(wǎng)絡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];
//加載網(wǎng)絡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"
附加親測效果圖