Add property control current page update action.

This commit is contained in:
Jack 2015-01-14 18:59:36 +08:00
parent 2f4e7642de
commit 75b7424d3f
2 changed files with 19 additions and 3 deletions

View File

@ -82,6 +82,8 @@ typedef NS_ENUM(NSUInteger, XLPagerTabStripDirection) {
@property (readonly) NSUInteger currentIndex;
@property BOOL skipIntermediateViewControllers;
// When user scroll the pager, waiting did end decelerating update page index, Default is NO.
@property BOOL shouldDidEndDeceleratingUpdatePage;
-(void)moveToViewControllerAtIndex:(NSUInteger)index;
-(void)moveToViewController:(UIViewController *)viewController;

View File

@ -71,6 +71,7 @@
_dataSource = self;
_lastContentOffset = 0.0f;
_skipIntermediateViewControllers = YES;
_shouldDidEndDeceleratingUpdatePage = NO;
}
- (void)viewDidLoad
@ -212,13 +213,20 @@
return fmodf(self.containerView.contentOffset.x, [self pageWidth]) / [self pageWidth];
}
- (void)updateCurrentPage
{
NSUInteger currentPage = [self pageForContentOffset:self.containerView.contentOffset.x];
if (currentPage != self.currentIndex){
self.currentIndex = currentPage;
}
}
-(void)updateContent
{
NSArray * childViewControllers = self.pagerTabStripChildViewControllers;
self.containerView.contentSize = CGSizeMake(CGRectGetWidth(self.containerView.bounds) * childViewControllers.count, self.containerView.contentSize.height);
NSUInteger currentPage = [self pageForContentOffset:self.containerView.contentOffset.x];
if (currentPage != self.currentIndex){
self.currentIndex = currentPage;
if (!self.shouldDidEndDeceleratingUpdatePage) {
[self updateCurrentPage];
}
[childViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
@ -296,6 +304,12 @@
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (self.shouldDidEndDeceleratingUpdatePage) {
[self updateCurrentPage];
}
}
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
if (self.containerView == scrollView && _originalPagerTabStripChildViewControllers){