[英]The UICollectionView cells are jerking while scrolling the UICollectionView
大家好,我是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设置图像时,可以直接从缓存中加载图像,它应该更加平滑。
尝试这样做
[_homeCellImage setShowActivityIndicatorView:YES];
[_homeCellImage setIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_homeCellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[dictionary objectForKey:@"user_image"],[QPCommonClass cropImageWithWidth:500 andHeight:500]]] placeholderImage:[UIImage imageNamed:@"defaultIcon"] options:SDWebImageRefreshCached];
[_qpQuestionImage setShowActivityIndicatorView:YES];
[_qpQuestionImage setIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_qpQuestionImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[dictionary objectForKey:@"image"],[QPCommonClass cropImageWithWidth:1400 andHeight:1200]]] placeholderImage:[UIImage imageNamed:@"question"] options:SDWebImageRefreshCached];
您必须在出队后添加这两行。
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.