Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved updatePageNumberForScrollView: when reversing #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion SMPageControl.m
Expand Up @@ -342,7 +342,14 @@ - (void)sizeToFit

- (void)updatePageNumberForScrollView:(UIScrollView *)scrollView
{
NSInteger page = (int)floorf(scrollView.contentOffset.x / scrollView.bounds.size.width);
// Use the trailing edge on reverse and leading edge on forward
NSInteger page;
if (self.currentPage * scrollView.bounds.size.width > scrollView.contentOffset.x) {
page = (int)ceilf(scrollView.contentOffset.x / scrollView.bounds.size.width);
} else {
page = (int)floorf(scrollView.contentOffset.x / scrollView.bounds.size.width);
}

self.currentPage = page;
}

Expand Down