Ios HeaderView和CollectionView之间的间隙
我有一个奇怪的错误,我的集合视图和标题视图之间有很大的差距(aIos HeaderView和CollectionView之间的间隙,ios,uicollectionview,uicollectionviewlayout,Ios,Uicollectionview,Uicollectionviewlayout,我有一个奇怪的错误,我的集合视图和标题视图之间有很大的差距(aUICollectionReusableView)。看起来是这样的: 其中蓝色突出显示的位是标题 在下一张图像中,我突出显示了UICollectionView: 有人会认为这与部分inset有关,但我的测试似乎不是这样。所有插图均为0。如果我删除标题(或将heightForHeaderInSection中的大小设置为0),问题就会消失 我在用电脑 我的代码如下: func viewDidLoad() { ... colle
UICollectionReusableView
)。看起来是这样的:
其中蓝色突出显示的位是标题
在下一张图像中,我突出显示了UICollectionView:
有人会认为这与部分inset
有关,但我的测试似乎不是这样。所有插图均为0。如果我删除标题(或将heightForHeaderInSection
中的大小设置为0),问题就会消失
我在用电脑
我的代码如下:
func viewDidLoad() {
...
collectionView.register(GridHeaderView.self, forSupplementaryViewOfKind: CHTCollectionElementKindSectionHeader, withReuseIdentifier: "albumInfoHeader")
...
}
func collectionView(_ collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let element = CHTCollectionElementKindSectionHeader
switch kind {
case CHTCollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: element,
withReuseIdentifier: "albumInfoHeader", for: indexPath) as! GridHeaderView
return headerView
default:
break
}
return UICollectionReusableView()
}
func colletionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
heightForHeaderInSection section: NSInteger) -> CGFloat {
switch section {
case 0:
return 49
default:
return 0
}
}
更新
我现在认为这是
chtcollectionviewwaterwalllayout
中的一个bug,并且已经提交了一个如果您在故事板中,您可以尝试选中UICollectionView的复选框“调整滚动视图插入”
您还可以尝试将其添加到视图控制器的viewDidLoad方法中:
collectionView.automaticallyAdjustsScrollViewInsets = false;
我已尝试在故事板和viewcontroller中禁用此功能,但无效。是否使用自动布局?是的,我使用。我试着在视图调试器中寻找奇怪的约束,但是看不到有多少相邻的单元格,或者它们也有相同的巨大空间?最后一个单元格到页脚或集合视图末尾的距离是否也有那么大?@johnyu这些单元格的间距正常,即它们之间没有很大的空间。页脚没有这样的间距布局的headerReferenceSize是什么?@johnyu我猜你指的不是我在上面代码中设置的值?我如何检查它?我没有设置headerReferenceSize,因为CHTCollectionLayout不支持它,它符合HeightForHeaderIn部分