我正在 UITableViewCell 中处理 UICollectionView。使用“UICollectionReusableView”作为标题 View 。 header view 的宽度是100。在我介绍header view 之前,CollectionViewCell 在CollectionView 的开头启动,这是符合预期的。在我放置标题 View 后,CollectionViewCell 从标题 View 宽度的末尾开始。我认为某处位置设置不正确。
CollectionView 滚动方向为 Horizontal。我使用 UICollectionViewFlowLayout 来呈现 CollectionViewCell。
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 5.0, left: 5.0, bottom: 5.0, right: 5.0)
layout.minimumInteritemSpacing = 8.0
layout.minimumLineSpacing = 5.0
layout.scrollDirection = .horizontal
layout.sectionHeadersPinToVisibleBounds = true
collectionView.collectionViewLayout = layout
我已经使用“referenceSizeForHeaderInSection”委托(delegate)设置标题 View 的大小。 我可能错了的任何提示。
最佳答案
而不是使用 UICollectionViewFlowLayout,你应该将它子类化并覆盖该方法 layoutAttributesForSupplementaryViewOfKind: 并相应地给出你的框架
关于ios - UICollectionViewCell 在 UICollectionViewReusableView 宽度之后启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55274589/