Permalink
Browse files

ATPagingView: Fix startup bugs caused by the new "set current page" f…

…eature
  • Loading branch information...
andreyvit committed Apr 26, 2011
1 parent 11f636d commit 11b2d4a0b6187f231aef2499e46ad5e97571263b
Showing with 8 additions and 4 deletions.
  1. +8 −4 ATPagingView/ATPagingView.m
@@ -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)
@@ -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;
@@ -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;
}

0 comments on commit 11b2d4a

Please sign in to comment.