大家好,我是 IOS 开发的新手,我有一个 UICollection,我在其中使用 SDWebImageCache 加载图像。问题是我的 UICollectionview 单元格在快速滚动时感觉像抽搐或颤抖。 下面我发布了使用 SDWebImageCache 加载图像的代码
[_homeCellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[dictionary objectForKey:@"user_image"],[QPCommonClass cropImageWithWidth:500 andHeight:500]]] placeholderImage:[UIImage imageNamed:@"defaultIcon"]];
[_qpQuestionImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[dictionary objectForKey:@"image"],[QPCommonClass cropImageWithWidth:1400 andHeight:1200]]] placeholderImage:[UIImage imageNamed:@"question"] options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){
[_qpHomeActivityIndicator setHidden:YES];
[_qpHomeActivityIndicator stopAnimating];
}];
其中 _homeCellImage 和 _qpQuestionImage 是 UIImageViews
最佳答案
- 确保在后台线程中加载图像。
- 加载图像后,请确保将其缓存。
现在通过cellForItem设置图片时,可以直接从缓存中加载图片,应该会流畅很多。
关于ios - UICollectionView 单元格在滚动 UICollectionView 时会抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35934069/