Created
March 3, 2016 12:04
-
-
Save Eridana/5e6d75ca68b4969e970e to your computer and use it in GitHub Desktop.
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 characters
#pragma mark - UIScrolViewDelegate | |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView | |
{ | |
CGFloat pageWidth = scrollView.frame.size.width; | |
float fractionalPage = scrollView.contentOffset.x / pageWidth; | |
NSInteger page = lround(fractionalPage); | |
if (page == 0) { | |
[self setFirstPageSelected]; | |
} | |
if (page == 1) { | |
[self setSecondPageSelected]; | |
} | |
if (page == 2) { | |
[self setThirdPageSelected]; | |
} | |
if (self.currentPage == 2 && fractionalPage > 2.0) { | |
[self showRegister]; | |
} | |
} | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | |
{ | |
[self stoppedScrolling:scrollView]; | |
} | |
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate | |
{ | |
if (!decelerate) { | |
[self stoppedScrolling:scrollView]; | |
} | |
} | |
- (void)stoppedScrolling:(UIScrollView *)scrollView | |
{ | |
CGFloat pageWidth = scrollView.frame.size.width; | |
float fractionalPage = scrollView.contentOffset.x / pageWidth; | |
self.currentPage = lround(fractionalPage); | |
} | |
#pragma mark - Paging | |
- (void)scrollToPage:(int)page | |
{ | |
[self.scrollView setContentOffset:CGPointMake(self.view.width * page, 0) animated:NO]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment