如何解决如何将NSCollectionLayoutBoundarySupplementaryItem与NSCollectionLayoutDecorationItem结合使用?
我正在使用类似于iOS 14插入分组样式的UICollectionViewCompositionalLayout,其中节中的所有单元格都在“卡”内,而节头位于“卡”外。我已经可以正常工作了,但是NSCollectionLayoutBoundarySupplementaryItem似乎不能很好地与背景NSCollectionLayoutDecorationItem一起玩。
似乎NSCollectionLayoutBoundarySupplementaryItem对齐到节的顶部时位于装饰视图和插图内容所覆盖的区域之外。默认情况下,布局通过标题的高度插入内容,但是标题放置在内容区域之外,因此如果不对标题的高度进行硬编码或尝试进行一些布局数学运算就无法对齐。正在努力避免。
以下是问题的屏幕截图:
这是我要重新创建的布局:
(忽略左插图-这部分很容易。)
您能够获得类似的功能吗?如果没有一些布局数学,是否有可能?
以下是相关代码:
// Create the layout item:
let size = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),heightDimension: .estimated(64))
let item = NSCollectionLayoutItem(layoutSize: size)
// Create the layout group:
let group = NSCollectionLayoutGroup.horizontal(layoutSize: size,subitem: item,count: 1)
// Create the layout header:
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),heightDimension: .estimated(48))
let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: headerSize,elementKind: UICollectionView.elementKindSectionHeader,alignment: .top)
// Create the section background:
let sectionBackground = NSCollectionLayoutDecorationItem.background(
elementKind: UICollectionView.elementKindSectionBackground)
sectionBackground.contentInsets = NSDirectionalEdgeInsets(all: Sizes.Insets.System.groupedSectionBackground)
// Create the layout section:
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(all: Sizes.Insets.System.groupedSectionBackground)
section.decorationItems = [sectionBackground]
section.boundarySupplementaryItems = [sectionHeader]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。