How to detect if the user has traveled a view in a UIScrollView?


I have a UIScrollView with a bunch of views that you can swipe back and forth between. I have a Next button that automatically scrolls the view forward. I want to keep the next button in sync with whenever I swipe forward/backwards. How can I detect if the user has swiped forward, and backwards so I can increment a counter respectively?

Found a solution via:

This will increment/decrement your page index when more than half of the next/previous page is displayed...

- (void)scrollViewDidScroll:(UIScrollView *)sender {
    CGFloat pageWidth = self.scrollView.frame.size.width;
    self.yourPageIndex = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;