Swift 4 UICollectionView detect end of scrolling

前端 未结 5 1526
野趣味
野趣味 2021-02-04 13:13

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

5条回答
  •  有刺的猬
    2021-02-04 13:49

    This is simple login which will go down to last index...!!!

    func ScrollEnd() {
              let lastSectionIndex = (self.collectionView?.numberOfSections)! - 1
             let lastItemIndex = (self.collectionView.numberOfItems(inSection: lastSectionIndex)) - 1
               let index =  IndexPath(item: lastItemIndex, section: lastSectionIndex)
               if messages.count != 0{
                   self.collectionView!.scrollToItem(at: index, at: UICollectionView.ScrollPosition.bottom, animated: false)
               }    }
    

提交回复
热议问题