Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
fix the selected item not call scrollViewDidScroll method inside scro…
Browse files Browse the repository at this point in the history
…ll top bar.
  • Loading branch information
xhzengAIB committed Mar 9, 2014
1 parent 1fe2346 commit ac905a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ICViewPager/ICViewPager/ViewPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ @interface ViewPagerController () <UIPageViewControllerDataSource, UIPageViewCon
@property (nonatomic) NSUInteger activeContentIndex;

@property (getter = isAnimatingToTab, assign) BOOL animatingToTab;
@property (getter = isShouldClicked, assign) BOOL shouldClicked;
@property (getter = isDefaultSetupDone, assign) BOOL defaultSetupDone;

// Colors
Expand Down Expand Up @@ -233,6 +234,8 @@ - (IBAction)handleTapGesture:(id)sender {
UIView *tabView = tapGestureRecognizer.view;
__block NSUInteger index = [self.tabs indexOfObject:tabView];

self.shouldClicked = YES;

//if Tap is not selected Tab(new Tab)
if (self.activeTabIndex != index) {
// Select the tab
Expand Down Expand Up @@ -386,6 +389,7 @@ - (void)setActiveContentIndex:(NSUInteger)activeContentIndex {
animated:YES
completion:^(BOOL completed) {

weakSelf.shouldClicked = NO;
weakSelf.animatingToTab = NO;

// Set the current page again to obtain synchronisation between tabs and content
Expand All @@ -403,6 +407,7 @@ - (void)setActiveContentIndex:(NSUInteger)activeContentIndex {
direction:(activeContentIndex < self.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:YES
completion:^(BOOL completed) {
weakSelf.shouldClicked = NO;
weakSelf.animatingToTab = NO;
}];
}
Expand Down Expand Up @@ -579,7 +584,7 @@ - (void)selectTabAtIndex:(NSUInteger)index {
return;
}

self.animatingToTab = YES;
self.animatingToTab = NO;

// Set activeTabIndex
self.activeTabIndex = index;
Expand Down Expand Up @@ -758,6 +763,7 @@ - (void)defaultSettings {
self.pageViewController.delegate = self;

self.animatingToTab = NO;
self.shouldClicked = NO;
self.defaultSetupDone = NO;
}
- (void)defaultSetup {
Expand Down Expand Up @@ -965,7 +971,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.actualDelegate scrollViewDidScroll:scrollView];
}

if (![self isAnimatingToTab]) {
if (![self isAnimatingToTab] && !self.shouldClicked) {
UIView *tabView = [self tabViewAtIndex:self.activeTabIndex];

// Get the related tab view position
Expand Down

2 comments on commit ac905a8

@desnyki
Copy link

@desnyki desnyki commented on ac905a8 Oct 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome solution, this request should be merged, although it has one bug. When you click on a tab instead of scrolling, shouldClicked is set to YES causing the tabs to move non asynchronously once again. What i did to fix it was, reset the variable (i.e. self.shouldClicked = NO;) in the scrollViewDidEndDraggin method.

@xhzengAIB
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!@desnyki

Fix the bug at here(https://github.com/desnyki/ICViewPager)?

Jack

Please sign in to comment.