加载单元格时UICollectionview滚动不连贯 [英] UICollectionview Scrolling choppy when loading cells

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

问题描述

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

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

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];mycell.imageView.image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]];返回菌丝;}

我的画廊滚动不连贯.我不明白为什么会这样.我尝试添加一个 NSCache 来缓存缩略图图像(认为创建图像可能很昂贵)但这对性能没有帮助.

我希望 UI 与股票应用程序一样流畅.

我现在怀疑它可能是 UICollectionViewCell prepareForReuse 中的某些东西,它可能阻止了 dequeueReusableCellWithReuseIdentifier 方法,但使用我无法找到的工具.p>

还有其他可能导致此问题的原因吗?有没有一种更快"的方法来准备 UICollectionViewCell 或以更快的方式 dequeue 它们?

解决方案

所以任何有滚动问题的人都应该这样做这个

在你的出队后添加这两行

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

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;
}

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.

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.

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

add these 2 lines after your dequeue

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆