Skip to content

Commit 0c3626e

Browse files
committed
Manually calculating the current scroll view center instead of relying on the convertPoint:toView: method to prevent the wrong currentPage to be calculated when the view is not visible.
1 parent aa9c130 commit 0c3626e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

SCPageViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SCPageViewController'
3-
s.version = '2.0.7'
3+
s.version = '2.0.8'
44
s.platform = :ios
55
s.ios.deployment_target = '5.0'
66

SCPageViewController/SCPageViewController.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,10 @@ - (NSUInteger)_calculateCurrentPage
776776
NSUInteger pageIndex = [pages indexOfObject:sortedPages[i]];
777777

778778
CGRect frame = [self.layouter finalFrameForPageAtIndex:pageIndex pageViewController:self];
779-
CGPoint centerOffset = [self.view convertPoint:self.scrollView.center toView:self.scrollView];
779+
780+
CGPoint centerOffset = self.scrollView.contentOffset;
781+
centerOffset.x += CGRectGetWidth(self.scrollView.bounds) / 2.0f;
782+
centerOffset.y += CGRectGetHeight(self.scrollView.bounds) / 2.0f;
780783

781784
if(CGRectContainsPoint(frame, centerOffset)) {
782785
return pageIndex;

0 commit comments

Comments
 (0)