Created
June 11, 2010 14:59
-
-
Save mattorb/434586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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