I have an Horizontal
UICollectionView
on my app and I want to load more data when the user reaches the end (or nearly to the end) of UICollectionView w
Implement method scrollViewDidScroll
of UIScrollViewDelegate
:
var isLoading: Bool = false
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let contentOffsetX = scrollView.contentOffset.x
if contentOffsetX >= (scrollView.contentSize.width - scrollView.bounds.width) - 20 /* Needed offset */ {
guard !self.isLoading else { return }
self.isLoading = true
// load more data
// than set self.isLoading to false when new data is loaded
}
}