问题描述
我正在尝试组合布局。我想在用户部分添加一个 + 添加用户标题。但是标题不会像在带有标题的 UICollectionView 上那样与其余部分一起滚动。 组合布局是否可能具有相同的行为? 我添加了部分代码和屏幕截图。
感谢您的帮助
import UIKit
struct UserSection:部分{
private let sectionId: String
init(sectionId: String) {
self.sectionId = sectionId
}
func layoutSection() -> NSCollectionLayoutSection {
let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .absolute(70),heightDimension: .absolute(100)),elementKind: sectionId,alignment: .leading)
header.pinToVisibleBounds = true
header.zIndex = Int.max
let item = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),heightDimension: .fractionalHeight(1)))
let group = NSCollectionLayoutGroup.horizontal(
layoutSize: NSCollectionLayoutSize(
widthDimension: .absolute(70),heightDimension: .estimated(100)),subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary
section.contentInsets.leading = 20
section.contentInsets.trailing = 20
section.contentInsets.bottom = 40
section.interGroupSpacing = 10
section.boundarySupplementaryItems = [header]
return section
}
}
// 在 UICollectionViewDatasource 中
func collectionView(_ collectionView: UICollectionView,viewForSupplementaryElementOfKind kind: String,at indexPath: IndexPath) -> UICollectionReusableView {
if indexPath.section == 1 {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,withReuseIdentifier: "userSectionHeader",for: indexPath) as! UserListHeader
return header
}
return UICollectionReusableView()
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)