我是子类UICollectionViewFlowLayout,以便在a中进行双向滚动UICollectionView.滚动对于较少数量的行和部分计数(100-200行和部分)工作正常,但是当我增加行和部分计数超过500(即250,000或更多单元格)时滚动时存在可见滞后UICollectionView.我已经跟踪了滞后的来源layoutAttributesForElementsInRect.我使用a Dictionary来保存UICollectionViewLayoutAttributes每个单元格以避免重新计算它并循环通过它以返回单元格的属性layoutAttributesForElementsInRect
import UIKit
class LuckGameCollectionViewLayout: UICollectionViewFlowLayout {
// Used for calculating each cells CGRect on screen.
// CGRect will define the Origin and Size of the cell.
let CELL_HEIGHT = 70.0
let CELL_WIDTH = 70.0
// Dictionary to hold the UICollectionViewLayoutAttributes for
// each cell. The layout attribtues will define the cell's size
// and position (x, y, and z index). I have found this process
// …Run Code Online (Sandbox Code Playgroud)