The easiest way to find fully visible CollectionView's Cell & ReusableView while scrolling
Detect CollectionView's Cell or ReusableView fully visible
And also can detect nested CollectionView's fully visibility
use VisibilityTrackableCollectionView and set delegate just like UICollectionView
class ViewController: UIViewController {
@IBOutlet weak var collectionView: VisibilityTrackableCollectionView!
collectionView.delegate = self
}
you can set boundary that to be detected
default boundary is superior viewController's view (not safeArea)
collectionView.setBoundary(.init(view: someView, mode: .safeArea))
Step 3. Adopt CollectionViewDelegateVisibleItems
with UICollectionViewDelegate
just like UICollectionViewDelegateFlowLayout
extension ViewController: CollectionViewDelegateVisibleItems {
func collectionView(_ collectionView: UICollectionView, firstTimeOfFullyVisibleItems items: [IndexPath]) {
}
func collectionView(_ collectionView: UICollectionView, allOfFullyVisibleItems items: [IndexPath]) {
}
func collectionView(_ collectionView: UICollectionView, supplementaryElementOfKind kind: String, firstTimeOfFullyVisibleItems items: [IndexPath]) {
}
func collectionView(_ collectionView: UICollectionView, supplementaryElementOfKind kind: String, allOfFullyVisibleItems items: [IndexPath]) {
}
}
- I want to refresh
firstTimeOfFullyVisibleItems
collectionView.refreshSeenData()
- I want to use nesting
just use VisibilityTrackableCollectionView
for nesting.
It's designed for reuse, so you don't have to worry about firstTimeOfFullyVisibleItems
.
- I want to refresh nested
VisibilityTrackableCollectionView
when superior has been refreshed
just call superior VisibilityTrackableCollectionView
's refreshSeenData()
that causes all of internal data refreshed.
Use Swift Package Manager (SPM)
VisibilityTrackableCollectionView is under MIT license.