YYWebImage icon indicating copy to clipboard operation
YYWebImage copied to clipboard

UIImageView不能做到无缝兼容GIF吗

Open dengbin9009 opened this issue 7 years ago • 3 comments

UIImageView 直接接受GIF的图不会有动态效果 必须要使用YYAnimatedImageView吗?

我看SD可以做到这一点?是我没有正确使用吗

现在的场景往往是后台传GIF图片就显示GIF,传其他就显示其他

dengbin9009 avatar May 08 '17 07:05 dengbin9009

SD 3.x use + animatedImageWithImages:duration: and decode GIF to UIImage array to draw. But it sometimes has performance issue.

YYImage use a abstract layer to save the infomation for each frame and draw with YYAnimatedImageView, it grab each frame and use CALayer to render with CADisplayLink. So this is why it can not show animation image on UIImageView.

SD 4.0 use FLAnimatedImageView for entire GIF support(Which is nearly the same method as YYImage) . When showing GIF on UIImageView, it only show the first frame.

dreampiggy avatar Jul 31 '17 16:07 dreampiggy

thx!
In this case, how do you fit GIF image from server?

dengbin9009 avatar Aug 01 '17 02:08 dengbin9009

@dengbin9009

So, if your imageView is just a subclass or just YYAnimatedImageView, use whatever image format that YYImage support is OK. Just use yy_setXXX or YYImage to set the image property.

But, if you want to add some behavior and create your own UIImageView subclass which do not subclass from YYAnimatedImageView. For the native GIF support, use +[UIImage(YYWebImage) yy_imageWithSmallGIFData:scale:] and set UIImageView.image (You can write an wrapper use whatever network framework such as AFNetworking and use YYImageCache to get the raw GIF data...really suck)

You can also use the old version SDWebImage(3.x) or even this simple category here:uiimage-from-animated-gif to get this type of GIF support to native UIImageView. They have nearly the same algorithm.

dreampiggy avatar Aug 01 '17 02:08 dreampiggy