Detect page change in UICollectionView

后端 未结 7 2243
醉酒成梦
醉酒成梦 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 03:44

    Use :

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
        CGFloat pageWidth = collectionView.frame.size.width;
        float currentPage = collectionView.contentOffset.x / pageWidth;
    
        if (0.0f != fmodf(currentPage, 1.0f))
        {
            pageControl.currentPage = currentPage + 1;
        }
        else
        {
            pageControl.currentPage = currentPage;
        }
    
        NSLog(@"Page Number : %ld", (long)pageControl.currentPage);
    }
    

    And if you are not using any pageControl, then ceil(currentPage) will be your current page number.

提交回复
热议问题