我正在努力使用 UICollectionViewCompositionalLayout 获得我想要的布局。下图是我正在尝试做的(以及我对分数宽度/高度的计算,根据我得到的结果,我只能假设它是不正确的。
我为尝试生成上述代码而编写的代码如下:
let leadingItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1/4), heightDimension: .fractionalHeight(1))
let nestedGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(3/4), heightDimension: .fractionalHeight(1))
let nestedItemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1/3), heightDimension: .fractionalHeight(1/2))
let outerGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalWidth(3/5))
let leadingItem = NSCollectionLayoutItem(layoutSize: leadingItemSize)
let nestedItem = NSCollectionLayoutItem(layoutSize: nestedItemSize)
let nestedGroup = NSCollectionLayoutGroup.horizontal(layoutSize: nestedGroupSize, subitem: nestedItem, count: 3)
let outerGroup = NSCollectionLayoutGroup.horizontal(layoutSize: outerGroupSize, subitems: [leadingItem, nestedGroup])
let section = NSCollectionLayoutSection(group: outerGroup)
return section
这会产生不希望的结果,如下图所示:
谁能解释我做错了什么并帮助我弄清楚如何实现我想要做的事情?
谢谢你。:)