我想使用SDWebImage
向imageView添加一些动画。我的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/