From 436da43608a362ea4f01b4a0b0f9419fa4399b45 Mon Sep 17 00:00:00 2001 From: Hari Karam Singh Date: Thu, 21 Mar 2013 15:08:52 +0000 Subject: [PATCH] Improved updatePageNumberForScrollView: when reversing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the UIScrollView for updating the page control's current page use the trailing edge on reverse instead of the leading edge.  This  removes funny edge affects on bounces and makes the forward & backward  scrolling experiences the same. --- SMPageControl.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SMPageControl.m b/SMPageControl.m index e3fe668..15717a6 100755 --- a/SMPageControl.m +++ b/SMPageControl.m @@ -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; }