我目前定义了以下组合布局:
func compose() -> NSCollectionLayoutSection {
let heroItemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(2/3),
heightDimension: .estimated(550)
)
let heroItem = NSCollectionLayoutItem(layoutSize: heroItemSize)
let sideKickItemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(0.5)
)
let sideKickItem = NSCollectionLayoutItem(layoutSize: sideKickItemSize)
let sideKickGroupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1/3),
heightDimension: .fractionalHeight(1.0)
)
let sideKickGroup = NSCollectionLayoutGroup.vertical(
layoutSize: sideKickGroupSize,
subitems: [sideKickItem, sideKickItem]
)
let topGroupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(550)
)
let topGroup = NSCollectionLayoutGroup.horizontal(
layoutSize: topGroupSize,
subitems: [heroItem, sideKickGroup]
)
return NSCollectionLayoutSection(group: topGroup)
}
这给了我以下布局:
理想的情况是绿色单元格 (the heroItem
) 具有一个应该领先的估计高度。紫色单元格 (the sideKickItem
) 应与绿色单元格一样高。
我不确定为什么布局最终使用高度550
作为最终高度,这使得紫色单元格的内容变得很大。
所以最后我希望布局如下图所示: