[英]The UICollectionView cells are jerking while scrolling the UICollectionView
Hi all i am a newbie in IOS Development and i have a UICollection where i am loading images with SDWebImageCache. 大家好,我是IOS开发中的新手,我有一个UICollection,可在其中使用SDWebImageCache加载图像。 The problem is my UICollectionview cell feels like jerking or shivering while scrolling fast. 问题是我的UICollectionview单元格在快速滚动时感觉像在抽搐或发抖。 Below I post my code for loading images with SDWebImageCache 下面我发布我的代码以使用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];
}];
where _homeCellImage & _qpQuestionImage are UIImageViews _homeCellImage和_qpQuestionImage是UIImageViews
Now when you set the image via cellForItem, the image can be loaded directly from cache, and it should be a lot smoother. 现在,当您通过cellForItem设置图像时,可以直接从缓存中加载图像,它应该更加平滑。
Try to do like this-- 尝试这样做
[_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];
You have to add these 2 lines after your dequeue. 您必须在出队后添加这两行。
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.