据我了解,每个NSCollectionLayoutGroup
都是通过为其父组指定的顺序呈现的,每个组还可以通过使用open class func vertical(layoutSize: NSCollectionLayoutSize, subitem: NSCollectionLayoutItem, count: Int) -> Self
来决定每个组以其类型呈现多少个项目。关于这一点,我想知道在渲染所有先前的项目之后是否可以渲染无限数量的项目(NSCollectionLayoutItem
)。
所需的版式
---------- <- 1 item
| | <- 2 items
---------- <- infinite item
----------
----------
----------
尽管没有给出计数,当前下面的代码仅显示defaultSection
private func createLayout2() -> UICollectionViewLayout {
let layout = UICollectionViewCompositionalLayout { (sectionIndex, layoutEnv) -> NSCollectionLayoutSection? in
let item = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0)
)
)
item.contentInsets = .init(top: 8, leading: 8, bottom: 8, trailing: 8)
// Featured
let bigSection = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(400)
),
subitem: item, count: 1
)
// Two tiles
let tileSecton = NSCollectionLayoutGroup.horizontal(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200)
),
subitem: item, count: 2
)
// Default items in list
let defaultSection = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(200)
),
subitems: [item]
)
// Section
let group = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0)
),
subitems: [bigSection, tileSecton, defaultSection]
)
return NSCollectionLayoutSection(group: group)
}
return layout
}