Skip to content

Commit

Permalink
ATPagingView: Fix startup bugs caused by the new "set current page" f…
Browse files Browse the repository at this point in the history
…eature
  • Loading branch information
andreyvit committed Apr 26, 2011
1 parent 11f636d commit 11b2d4a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ATPagingView/ATPagingView.m
Expand Up @@ -132,8 +132,10 @@ - (UIView *)viewForPageAtIndex:(NSUInteger)index {
}

- (void)configurePages {
if (_scrollView.frame.size.width == 0)
if (_scrollView.frame.size.width <= _gapBetweenPages + 1e-6)
return; // not our time yet
if (_pageCount == 0 && _currentPageIndex > 0)
return; // still not our time

// normally layoutSubviews won't even call us, but protect against any other calls too (e.g. if someones does reloadPages)
if (_rotationInProgress)
Expand Down Expand Up @@ -162,6 +164,8 @@ - (void)configurePages {
NSLog(@"newPageIndex == %d", newPageIndex);
#endif

newPageIndex = MAX(0, MIN(_pageCount, newPageIndex));

// calculate which pages are visible
int firstVisiblePage = self.firstVisiblePageIndex;
int lastVisiblePage = self.lastVisiblePageIndex;
Expand Down Expand Up @@ -298,10 +302,10 @@ - (void)setCurrentPageIndex:(NSInteger)newPageIndex {
#ifdef AT_PAGING_VIEW_TRACE_LAYOUT
NSLog(@"setCurrentPageIndex(%d): _scrollView.frame == %@", newPageIndex, NSStringFromCGRect(_scrollView.frame));
#endif
if (_scrollView.frame.size.width > 0 && fabsf(_scrollView.frame.origin.x - (-_gapBetweenPages/2)) < 1e-6)
if (_scrollView.frame.size.width > 0 && fabsf(_scrollView.frame.origin.x - (-_gapBetweenPages/2)) < 1e-6) {
_scrollView.contentOffset = CGPointMake(_scrollView.frame.size.width * newPageIndex, 0);
else
_currentPageIndex = newPageIndex;
}
_currentPageIndex = newPageIndex;
}


Expand Down

0 comments on commit 11b2d4a

Please sign in to comment.