相关文章推荐

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a UIImageView and set the image through kf.setImage() .
It works fine, except that the ImageView is flickering once each time I call kf.setImage() again on the same Image View, even if the image is exactly the same and loaded from the Cache.

Is there a way to turn this off or avoid re-setting the image?

Thanks!

Reproduce

[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]

This is due to the image is already released from memory cache and will be loaded again from disk cache, with a nil placeholder. You could try to set images with .keepCurrentImageWhileLoading to see whether it could work:

imageView.kf.setImage(with: url, options: [.keepCurrentImageWhileLoading])

Hi @onevcat ,

I am also seeing this even with keepCurrentImageWhileLoading .

I think my issue is with the transition. Since even with that flags it tries to set to nil the placeholder. Or am I using it wrong there?

Thanks,

@hernangonzalez 👍

@renshaw1
BTW, if you are using it in a reusable cell in table view or collection, maybe the flickering comes from the cell reusing. You could also try:

cell.imageView.kf.setImage(with: url, placeholder: cell.imageView.image)

to use the current image as your loading placeholder to prevent it.

.keepCurrentImageWhileLoading seems to work.
In my situation, I got a blink because I called collectionView.reloadSections(indexSet:) on a section that contains a cell that displays an image. The problem with that is reloadSections forces the collectionView to create new cells (as in new pointers) for these sections. Since it's displaying a new cell, the imageView starts off as its backgroundColor, then fades in the image.

If the problem happens due to lack of memory cache, another solution worths to try is adding a [ .load​Disk​File​Synchronously option]( https://kingfisher.onevcat.com/kingfisheroptionsinfoitem/#kingfisheroptionsinfoitem.loaddiskfilesynchronously . It turns the async loading from disk to sync behavior and prevents the possible flickering.

 
推荐文章