UICollectionViewFlowLayout的一个子类,可以将项扩展以填充空间,针对大量项集进行了优化,受到NHBalancedFlowLayout的启发。
查看演示应用程序以获取示例。
ZLBalancedFlowLayout支持UICollectionViewFlowLayout的所有属性和相应的委托方法,包括minimumLineSpacing
、minimumInteritemSpacing
、sectionInset
等。
使用rowHeight
调整项目高度。
/// The ideal row height of items in the grid
var rowHeight = CGFloat(100)
/// The option to enforce the ideal row height by changing the aspect ratio of the item if necessary.
var enforcesRowHeight = false
ZLBalancedFlowLayout使用动态规划技术预先找出单元格的最优分区。基准测试基于prepareLayout
的计时。
NumSections | NumItemsPerSection | ZLBalancedFlowLayout | UICollectionViewFlowLayout |
---|---|---|---|
1 | 100 | 0.0517209768295288 | 0.00196903944015503 |
1 | 1000 | 0.565874993801117 | 0.0149750113487244 |
1 | 3000 | 递归溢出,尚未尾优化 | 0.0408549904823303 |
10 | 100 | 0.523442983627319 | 0.0157199501991272 |
10 | 1000 | 5.28750801086426 | 0.130671977996826 |
100 | 100 | 4.89241003990173 | 0.118210017681122 |
NumSections | NumItemsPerSection | ZLBalancedFlowLayout | UICollectionViewFlowLayout |
---|---|---|---|
1 | 100 | 0.0160560011863708 | 0.000555038452148438 |
1 | 1000 | 0.228259027004242 | 0.0039139986038208 |
1 | 3000 | 1.20643001794815 | 0.0141730308532715 |
10 | 100 | 0.158486008644104 | 0.0039370059967041 |
10 | 1000 | 2.26102298498154 | 0.0399309992790222 |
100 | 100 | 1.60317003726959 | 0.0364070534706116 |
100 | 1000 | 21.678355038166 | 0.385994970798492 |
ZLBalancedFlowLayout受MIT许可证保护。有关更多信息,请参阅LICENSE文件。
演示应用程序中的照片是从国家地理杂志选取的。