滚动UICollectionView时,UICollectionView单元格正在抖动

时间:2016-03-11 06:59:15

标签: ios objective-c iphone uicollectionviewcell sdwebimage

大家好我是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

3 个答案:

答案 0 :(得分:2)

  1. 确保在后台线程中加载图像。
  2. 加载图像后,请务必对其进行缓存。
  3. 现在,当您通过cellForItem设置图像时,图像可以直接从缓存加载,而且应该更顺畅。

答案 1 :(得分:0)

尝试这样做 -

[_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];

答案 2 :(得分:0)

你出队后必须添加这两行。

cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;