Detect page change in UICollectionView

后端 未结 7 2108
醉酒成梦
醉酒成梦 2021-01-31 03:35

I tried finding this question for a while but could not find this problem\'s answer. My problem is that i have a UICollectionView and the Scroll Direction is

相关标签:
7条回答
  • 2021-01-31 04:10

    Based on @Shankar BS 's answer I've implemented it like this in Swit. Keep in mind that CollectionViewDelegate conforms to ScrollViewDelegate:

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        let pageWidth = scrollView.frame.size.width
        let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
        print("page = \(page)")
    }
    
    0 讨论(0)
提交回复
热议问题