YYWebImage
YYWebImage copied to clipboard
UIImageView不能做到无缝兼容GIF吗
UIImageView 直接接受GIF的图不会有动态效果 必须要使用YYAnimatedImageView吗?
我看SD可以做到这一点?是我没有正确使用吗
现在的场景往往是后台传GIF图片就显示GIF,传其他就显示其他
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.
thx!
In this case, how do you fit GIF image from server?
@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.