我有一个带有注册的elementKindSectionHeader
标头的集合视图。集合视图中的单元格当前设置为(width: view.frame.width, height: view.frame.height)
,以进行演示。
目前,我得到:(标题包括封面照片和菜单栏)
但是我希望单元格水平滚动而不是垂直滚动。我显然也希望标题保留在原处。我已经有如下所述的referenceSizeForHeaderInSection
方法:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return .init(width: view.frame.width, height: 300)
}
当我将collectionView更改为具有水平滚动时,这似乎无关紧要。标题占据了整个屏幕以及更多内容:
if let layout = collectionViewLayout as? UICollectionViewFlowLayout {
layout.scrollDirection = .horizontal
}
我有一个单独的Header类,用于渲染注册为UICollectionReusableView
的封面照片和菜单栏等,并且我的收藏夹视图按如下方式使用它:
// Register cell classes
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellId)
self.collectionView.register(HeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerId)
self.collectionView.contentInset = UIEdgeInsets(top: 90, left: 0, bottom: 0, right: 0)
self.collectionView?.scrollIndicatorInsets = UIEdgeInsets(top: 90, left: 0, bottom: 0, right: 0)
使用这样的标题区域是我的新手。我该如何像第一张照片一样覆盖页眉来覆盖UICollectionReusableView
中的滚动条?还是我可以尝试另一种聪明的方法?