protocol HideHeaderViewDelegate {
func hideHeaderView(hide: Bool)
}
class HeaderView: UICollectionReusableView {
var delegate: HideHeaderViewDelegate?
@IBOutlet weak var hideButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
@IBAction func hideButtonAction(_ sender: Any) {
self.frame.size = CGSize.zero
guard let delegate = delegate else { return }
delegate.hideHeaderView(hide: true)
}
}
extension ViewController: HideHeaderView {
func hideHeaderView(hide: Bool) {
if hide == true {
print(hide)
// invalidate your layout here
}
}
}
func collectionView(_ collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String,
at indexPath: IndexPath) -> UICollectionReusableView {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader,
withReuseIdentifier: "headerView", for: indexPath) as! HeaderView
headerView.delegate = self
return headerView
}