ios - 如何使用 UICollectionView 使用 SDWebImage 添加溶解动画

标签 ios iphone user-interface sdwebimage collectionview

我想使用SDWebImageimageView添加一些动画。我的collectionView委托(delegate)函数在这里

- (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;
        }];    
    }];
}

SDWebImage下载图片并设置imageView的图片是可以的。 但是当我调用[collection reloadData]方法时,这些imageViews再次溶解。

我知道原因,但没有解决办法。

最佳答案

我最近一直在努力解决同样的问题,我想我已经想出了一个易于使用的解决方案。可以看到here .

基本上,它是一个 UIImageView 类别,仅当从网络下载或从磁盘缓存获取图像时才使用动画来设置图像(这花费的时间要少得多,但仍然很明显)。如果它来自内存 - 不需要动画。当您重新加载 Collection View 时,图像显然已缓存在内存中,因此不会使用动画。让我知道它是否对您有用。

关于ios - 如何使用 UICollectionView 使用 SDWebImage 添加溶解动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29161272/

相关文章:

iphone - 如何更有效地编写一些条件代码?

iphone - iphone上tableview上的sqlite db上的文本搜索太慢了

android:如何调试用户界面

objective-c - 在状态栏上加载栏?

ios - 在无效的 indexPath 处捕获了对 rect 的 NSInternalInconsistencyException 请求

iphone - UIView不直接显示

iphone - 构建数据驱动的 UI

qt - 为什么我没有 Qt Gui Application 选项?

html - <header> 和 <footer> 实际上是做什么的?

ios - 支持 iOS6 到 9 的后台位置更新