【问题标题】:The UICollectionView cells are jerking while scrolling the UICollectionViewUICollectionView 单元格在滚动 UICollectionView 时出现抖动
【发布时间】:2016-03-11 06:59:14
【问题描述】:

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

【问题讨论】:

  • 注释掉以上行是否消除了抽搐?

标签: ios objective-c iphone uicollectionviewcell sdwebimage


【解决方案1】:
  1. 确保在后台线程中加载图像。
  2. 加载图像后,请确保对其进行缓存。

现在当你通过cellForItem设置图片时,可以直接从缓存中加载图片,应该会流畅很多。

【讨论】:

    【解决方案2】:

    尝试这样做--

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

    【讨论】:

      【解决方案3】:

      您必须在 dequeue 之后添加这两行。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-04
        • 2016-02-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多