Skip to content

Instantly share code, notes, and snippets.

@Eridana
Created March 3, 2016 12:04
Show Gist options
  • Save Eridana/5e6d75ca68b4969e970e to your computer and use it in GitHub Desktop.
Save Eridana/5e6d75ca68b4969e970e to your computer and use it in GitHub Desktop.
#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