实现下图的效果
层次关系为:
- Collection View 有一个 header,
header 上面有一个 scroll view
- Collection View 还有很多 cell
图中可视区域内,有 6 个
效果是,点击 scroll view 上面的 item,
可以更新下面 cell 的内容
第一部分,自定义布局 Collection View layout
布局精华
class HanGridLayout: UICollectionViewLayout {
override public func prepare() {
guard let collectionView = collectionView else {
return
}
prepareCache()
contentHeight = 0
// 配置 header 的位置,
let headerH = layout.headSize.height
let headerIP = IndexPath(item: 0, section: 0)
let headerAttributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: CommonComponent.head