CollectionView放慢速度

CollectionView放慢速度

本文介绍了iOS 9 CollectionView放慢速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为iOS8开发我的应用程序,并且在滚动速度方面没有任何问题。在我升级到iOS9的那一刻,collectionView变得非常震撼和惊人。我无法指出任何具体原因。在我的集合视图中,我有使用第三方库(SDWebImage)的图像项目,我还使用自定义布局库来实现双列布局。是否有任何明显的原因可能发生这种情况?

I have been developing my app for iOS8, and haven't really had any issues regarding the scrolling speed. The moment I have upgraded to iOS9 the collectionView became very jumpy and staggering. I cant point out to any specific reason why. In my collection view, I have items with images that uses 3rd party library (SDWebImage) and I also use a custom layout library to achieve double column layout. Is there any obvious reason why this could be happening?

推荐答案

在这种情况下,问题是关于在imageView上处理后备图像。

In this case the problem was about handling fallback images on the imageView.

简而言之,CollectionView中的每个项目都有一个UIImageView。每个UIImageView都有一个后备图像,以防实际图像无法解析(例如,网址被破坏)。所以,这些后备图像设置的方式在我的应用程序中是错误的!每次在视口中渲染一个collectionview项时,我都会设置图像。

Briefly, each item in the CollectionView has an UIImageView. Each UIImageView has a fallback image in case the actual image doesnt resolve (the url is broken for example). So, the way these fallback images set was wrong in my app! I have set images every time a collectionview item is rendered in the viewport.

UIImageView * fallback = [UIImage imageNamed:@"imageName"];

这会使滚动错开。有趣的是,它不是iOS8上的问题,而只是在iOS9中。

was called everytime, which makes the scroll staggered. Interestingly it wasnt an issue on iOS8 but only in iOS9.

因此,当我开始从预先创建的图像字典中读取而不是每次都创建一个新图像时,滚动视图开始变得平滑。

So when I started reading from a precreated dictionary of images instead of creating a new one every time, the scroll view started become smooth again.

希望这有助于那些有同样问题的人。

Hope this helps to those having the same issue.

这篇关于iOS 9 CollectionView放慢速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:05