Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
- (void)scrollViewDidScroll:(UIScrollView *)sender {
BOOL isScrollingRight = _scrollView.contentOffset.x > _previousContentOffsetX;
_mostRecentScrollWasRight = isScrollingRight;
_previousContentOffsetX = _scrollView.contentOffset.x;
CGFloat pageWidth = _scrollView.frame.size.width;
int scrollingToPageNum = isScrollingRight ? (ceil((_scrollView.contentOffset.x - pageWidth) / pageWidth) + 1) : (floor((_scrollView.contentOffset.x -pageWidth) / pageWidth) + 1);
int percentOfScrollToPageOnscreen = isScrollingRight ? floor((((int)_scrollView.contentOffset.x % (int)pageWidth) / pageWidth)*100)
: floor((1 - ((int)_scrollView.contentOffset.x % (int)pageWidth) / pageWidth) * 100);
// load the controllers/views you deem appropriate based on having the above info
}
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView { //landed on a page
int landingPage = floor((self._scrollView.contentOffset.x - self._scrollView.frame.size.width / _pageCount) / self._scrollView.frame.size.width) + 1;
if (landingPage == 0 ) {
[_scrollView scrollRectToVisible:CGRectMake(_pageSize.size.width*(_pageCount-2),0,_pageSize.size.width,_pageSize.size.height) animated:NO];
} else if (landingPage == (_pageCount-1)) {
[_scrollView scrollRectToVisible:CGRectMake(_pageSize.size.width*1,0,_pageSize.size.width,_pageSize.size.height) animated:NO];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment