[英]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.