0
사용자 정의 레이아웃이있는 컬렉션 뷰에서 무한 스크롤을 구현하려고합니다. 때로는 심지어 20 번 연속 호출되는, 세포의 많은이 콜렉션 뷰에 삽입 원인무한 스크롤을 구현하는 동안 scrollViewDidLoad가 여러 번 호출되었습니다.
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
//make sure collection view is on screen
if collectionView?.window == nil { return }
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.size.height {
print("scroll ended")
getNextTenProducts()
collectionView?.reloadData()
}
}
그러나, 인쇄 문이 호출되는 여러 번 :
는 검색 후 나는이 방법을 발견했다.
해결 방법이 있습니까?
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if collectionView?.window == nil { return }
let offsetTolerance = CGFloat(30)
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.size.height + offsetTolerance, !scrollViewReachedBottom {
print("scroll ended")
scrollViewReachedBottom = true
} else if offsetY < contentHeight - scrollView.frame.size.height - offsetTolerance {
scrollViewReachedBottom = false
}
}
: