問題主要點:
- 項目之前是采用如下方案加載gif文件(sd_animatedGIFWithData:imageData)
UIImageView *imgView = [UIImageView new];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.frame = CGRectMake(30, 20, w, h);
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"loading" ofType:@"gif"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
imgView.backgroundColor = [UIColor clearColor];
imgView.image = [UIImage sd_animatedGIFWithData:imageData];
[loadingView addSubview:imgView];
-
伙伴那邊更新了Podfile文件,今天本地pod update,發(fā)現(xiàn)關于SDWebImage報了兩個錯誤(一個是api多了參數(shù),一個是api更新,找到錯誤之后,順藤摸瓜就能解決),錯誤解決之后,發(fā)現(xiàn)gif動畫加載是空白的。最先考慮是不是gif丟失了 導致data為空,斷點發(fā)現(xiàn)不是,初步猜想應該是更新之后api改變了。后面就是一系列的猜想認證,伙伴是可以的,讓他也更新pod,發(fā)現(xiàn)出來跟我一樣的問題,進一步證實了我的猜想,既然知道是api更新導致的問題,那接下里就好辦了。
可以發(fā)現(xiàn)SDWebImage之前是3.8.2,現(xiàn)在最新的版本是4.0.0 -
github上搜索SDWebImage,會發(fā)現(xiàn)如下提示,哦,原來是這樣的??
原來4.0之后,就FLAnimatedImageView這個代替了,用pod 'SDWebImage/GIF'導入這個庫使用就行了 改了之后的代碼如下:
FLAnimatedImageView *imgView = [FLAnimatedImageView new];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.frame = CGRectMake(30, 20, w, h);
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]]pathForResource:@"loading" ofType:@"gif"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
imgView.backgroundColor = [UIColor clearColor];
imgView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];
[loadingView addSubview:imgView];
補充:
網(wǎng)上大概搜了下加載本地gif的幾種方法,其實也可以用UIWebview,代碼如下:
NSData *data = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"loading" ofType:@"gif"]];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(30, 20, w, h)];
webView.contentMode = UIViewContentModeScaleAspectFit;
[webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
[loadingView addSubview:webView];
但是苦于不能等比例縮放gif圖片大小,大概要用到js來控制,就舍棄了,還是用了SDWebImage,這個以后補充更新。

