Detect page change in UICollectionView

后端 未结 7 2189
醉酒成梦
醉酒成梦 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条回答
  •  萌比男神i
    2021-01-31 03:46

    You can get the current page like below, index will be from 0 to (total page - 1)

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
     {
        CGFloat pageWidth = scrollView.frame.size.width;
        int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        NSLog(@"Current page -> %d",page);
    }
    

提交回复
热议问题