Created
June 11, 2010 14:59
-
-
Save mattorb/434586 to your computer and use it in GitHub Desktop.
Revisions
-
mattorb revised this gist
Jun 11, 2010 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,18 +9,16 @@ - (void)scrollViewDidScroll:(UIScrollView *)sender { 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]; } } -
mattorb created this gist
Jun 11, 2010 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ - (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); } - (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; UIViewController *controller; if (landingPage == 0 ) { [_scrollView scrollRectToVisible:CGRectMake(_pageSize.size.width*(_pageCount-2),0,_pageSize.size.width,_pageSize.size.height) animated:NO]; controller = [_viewControllers objectAtIndex:_pageCount-2]; } else if (landingPage == (_pageCount-1)) { [_scrollView scrollRectToVisible:CGRectMake(_pageSize.size.width*1,0,_pageSize.size.width,_pageSize.size.height) animated:NO]; controller = [_viewControllers objectAtIndex:1]; } }