UICollectionview加载单元格时滚动波纹

我在我的应用程序利用UICollectionView 。 细胞约70,70大小。 我正在使用ALAssets中的ALAssetLibrary中存储的列表中的ALAssetLibrary

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

 -(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来caching缩略图(思考也许创build的图像是昂贵的),但这并没有帮助性能。

我期望的界面像股票应用程序一样but but。

我现在怀疑它可能是UICollectionViewCell prepareForReuse中的东西,可能会阻止dequeueReusableCellWithReuseIdentifier方法,但使用工具,我无法find这个。

任何其他的事情可能是造成这种情况? 有没有一种“更快”的方式来准备UICollectionViewCell或以更快的速度将它们dequeue

所以有滚动问题的人应该这样做

在你出队后添加这两行

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

我会假设“不稳定”来自UIImage分配,而不是任何与dequeueReusableCellWithReuseIdentifier方法。 我会尝试做一个后台线程的图像分配,看看是否使事情更多一点but。。

 -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { mycell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) { // Load image on a non-ui-blocking thread UIImage *image = [[UIImage imageWithCGImage:[alassetList objectAtIndex:indexpath.row] thumbnail]]; dispatch_sync(dispatch_get_main_queue(), ^(void) { // Assign image back on the main thread mycell.imageView.image = image; }); }); return mycell; } 

更多细节可以在这里find: https : //developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html

使用NSURLConnection的sendAsynchronousRequest:queue:completionHandler:加载图像sendAsynchronousRequest:queue:completionHandler:

 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [cell.imageView setImage:[UIImage imageWithData:data]]; }]; 

勾选剪辑子视图,在属性检查器中select不透明,并勾选启用分页。

如果有人正在使用PhImageManager,closures同步解决了这个问题。 (deliveryMode = .FastFormat也可以提供额外的性能增强,但是权衡是缩略图的质量会降低)

  let option = PHImageRequestOptions() option.deliveryMode = .Opportunistic option.synchronous = false PHImageManager().requestImageForAsset(phAsset, targetSize: CGSizeMake(2048, 2048), contentMode: .AspectFit, options: option, resultHandler: { (image, objects) in self.imageView.image = image! }) 

我有问题与UICollectionView滚动。

什么工作(几乎)像我的魅力:我用PNG缩略图90×90填充单元格。 我说几乎是因为第一个完整的滚动不是那么顺利,但从来没有崩溃了…

在我的情况下,单元格大小是90×90。

我以前有过很多原始的png大小,当png的原始大小大于1000×1000(第一次滚动时很多崩溃)时,它非常不稳定。

所以我在UICollectionView上select90x90(或类似),并显示原始PNG(不pipe大小)。 希望这可以帮助别人。