I want to add some animation to the imageView with the SDWebImage
.and my collectionView delegate function is here
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Cell *cell = (Cell *)[cv dequeueReusableCellWithReuseIdentifier:@"identifier" forIndexPath:indexPath];
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:URL] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
cell.imageView.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{
cell.imageView.alpha = 1;
}];
}];
}
It's OK during the SDWebImage download the image and set the image of the imageView.
But when I call the [collection reloadData]
method,these imageViews dissolve again.
I know the reason but I do not have a solution of it.
I've been struggling with the same issue lately and I think I've came up with an easy to use solution. You can see it here.
Basically it's a UIImageView category that uses animation to set image only if it's downloaded from the web or fetched from disk cache (which takes far less time, but still noticeable). If it comes from memory - no animation needed. When you reload your collection view images are obviously cached in memory, so no animation will be used. Let me know if it worked for you.