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

advertisements

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: https://github.com/cwalcott/UIScrollView-Paging/blob/d0160aa2ad011bf47e1e2e78327ae840c3614107/README.txt

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;
}