Ios 如何在scrollViewDidScroll中获取对collectionView标题的引用?
我正在实现collectionView的scollViewDidScroll委托方法,我需要获取对我的头的引用,以便访问header.swift文件中的一些出口Ios 如何在scrollViewDidScroll中获取对collectionView标题的引用?,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在实现collectionView的scollViewDidScroll委托方法,我需要获取对我的头的引用,以便访问header.swift文件中的一些出口 func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerID, for: indexPath) as! publicEventsHeader
header.headerImage.image = UIImage(named: "stadium", in: nil, with: nil)
header.collectionView.delegate = header
header.collectionView.dataSource = header
return header
}
那么,如何在scrollViewDidScroll方法中访问此委托方法的标题呢?使用
collectionView
的方法的VisibleSupplementaryView(ofKind:)
来获取所有当前可见的headerViews
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let headersViews = (scrollView as? UICollectionView)?.visibleSupplementaryViews(ofKind: UICollectionElementKindSectionHeader) {
//add your code here...
}
}