之前的使用方法
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网址
pod 'sdwebimage/gif'to your podfile. to use it, simply make sure you useflanimatedimageviewinstead ofuiimageview. note: there is a backwards compatible feature, so if you are still trying to load a gif into auiimageview, it will only show the 1st frame as a static image. important: flanimatedimage only works on the ios platform. for os x, usensimageviewwithanimatesset toyesto show the entire animated images andnoto 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];
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论