UICollectionview加载单元格时滚动波动

UICollectionview加载单元格时滚动波动

本文介绍了UICollectionview加载单元格时滚动波动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个使用 UICollectionView 的图库。细胞大小约为70,70。我在列表中存储的库中的 ALAssetLibrary 中使用 ALAssets

I have a gallery in my app utilizing a UICollectionView. The cells are approximately 70,70 size. I am using ALAssets from the ALAssetLibrary in the gallery which I have stored in a list.

我使用通常的模式来填充单元格:

I am using the usual pattern for populating the cells:

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

  mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
  mycell.imageView.image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]];
  return mycell;
}

我的画廊滚动起伏不定。我不明白为什么会这样。我已经尝试添加一个NSCache来缓存缩略图(想想可能创建的图像很昂贵),但这对性能没有帮助。

My gallery is scrolling choppy. I don't understand why this is. I've tried adding a NSCache to cache the thumbnail images (thinking maybe creating the images was expensive) but this did not help for the performance.

我希望用户界面与股票应用程序一样黄油。

I would expect the UI to be as buttery as the stock app.

我现在怀疑它可能是 UICollectionViewCell prepareForReuse 中的内容可能会拿着 dequeueReusableCellWithReuseIdentifier 方法但是使用我无法找到的工具。

I am now suspecting it may be something in the UICollectionViewCell prepareForReuse that may be holding up the dequeueReusableCellWithReuseIdentifier method but using instruments I was not able to find this.

还有其他任何东西可能是造成这种情况?是否有一种更快的方式来更快地准备 UICollectionViewCell 出列

Any other thing that may be be causing this? Is there a "faster" way to prepare the UICollectionViewCell or to dequeue them in a faster fashion?

推荐答案

所以任何有滚动问题的人都应该

So anybody having scrolling issues should do this

在您出列后添加这两行

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

这篇关于UICollectionview加载单元格时滚动波动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 15:10