How to detect which page is showing now in UIScrollView PageEnabled in iOS


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    static NSInteger previousPage = 0;
    CGFloat pageWidth = scrollView.frame.size.width;
    float fractionalPage = scrollView.contentOffset.x / pageWidth;
    NSInteger page = lround(fractionalPage);
    if (previousPage != page) {
        // Page has changed, do your thing!
         previousPage = page;
    }
}

-ktrkathir

Author: Kathiresan Murugan

Associate Technical Lead - iOS

Leave a comment