Sdwebimage: PlaceholderImage doesn't work with animated Gifs.

Created on 10 Feb 2018  路  3Comments  路  Source: SDWebImage/SDWebImage

When loading a remote image with sd_setImage, the placeholder image doesn't work with animated gifs. It won't accept FLAnimatedImage (since FLAnimatedImage is not a UIImage subclass) and won't animate a UIImage that is an animated GIF.

GIF usage

Most helpful comment

@rpstro02 You can pass a UIAnimatedImage created by -[UIImage animatedImageWithImages:duration:]. Which can be shown correctlly. You can call -[UIImage sd_animatedGIFWithData:] to create one.

However, since FLAnimatedImage is not a UIImage subclass, you can not pass one to do placeholder. This will be fixed into 5.x release because we drop out that FLAnimatedImage subspec and introduce own SDAnimatedImage, which is a UIImage subclass.

For now, just use some other way like using UIAnimatedImage, or set the placeholder yourself before calling sd_setImageWithURL: with SDWebImageDelayPlaceholder 馃槄

All 3 comments

@rpstro02 You can pass a UIAnimatedImage created by -[UIImage animatedImageWithImages:duration:]. Which can be shown correctlly. You can call -[UIImage sd_animatedGIFWithData:] to create one.

However, since FLAnimatedImage is not a UIImage subclass, you can not pass one to do placeholder. This will be fixed into 5.x release because we drop out that FLAnimatedImage subspec and introduce own SDAnimatedImage, which is a UIImage subclass.

For now, just use some other way like using UIAnimatedImage, or set the placeholder yourself before calling sd_setImageWithURL: with SDWebImageDelayPlaceholder 馃槄

UIImage.sd_animatedGIF(with: animatedPlaceholderData)

This works. Thank you for the reply.

@rpstro02 Maybe a better way. We can expose the associate object in FLAnimatedImage+WebCache. Then you can create a new FLAnimatedImage, bind this to your UIImage placeholder and call the sd_setImageWithURL:.

In 4.3.0 we introduce this to fix some issue and "store" the FLAnimatedImage into memory cache. But it's read-only because at that time I think it's should be a advacend feature and user should avoid touching this. Now I think it's time to open the ability to set that property.

See #2220

Was this page helpful?
0 / 5 - 0 ratings