【发布时间】:2019-07-25 18:58:50
【问题描述】:
我已经声明了如下的集合视图
lazy var collectionView:UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = UICollectionViewFlowLayout.automaticSize
layout.minimumLineSpacing = 52
layout.sectionInset = UIEdgeInsets(top: 25, left: 0, bottom: 30, right: 0)
var collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = UIColor.white
collectionView.showsVerticalScrollIndicator = false
collectionView.register(XXXCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
collectionView.register(XXXHeaderViewCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)
collectionView.delegate = self
return collectionView
}()
并在委托下实现,控制权仅来自 referenceSizeForHeaderInSection 方法,而不是 viewForSupplementaryElementOfKind
public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath)
return headerView
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
let size = CGSize(width: self.collectionView.bounds.width, height: 200)
return size
}
非常感谢任何帮助。
【问题讨论】:
-
修复了这个问题。我有一个 customDataSource,它有这个方法的实现。
标签: ios uicollectionview