Get Visible IndexPath UICollectionView in Swift

前端 未结 5 1882
-上瘾入骨i
-上瘾入骨i 2021-02-07 11:02

How to get visible IndexPath while scrolling in collectionView,I referred many link1,link2 But indexPathForCell is not suppor

5条回答
  •  误落风尘
    2021-02-07 11:23

    This will work fine.

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) {
    
        let visibleIndex = Int(targetContentOffset.pointee.x / collectionView.frame.width)
        print(visibleIndex)
    
    }
    

提交回复
热议问题