Skip to content

Commit

Permalink
Fix crashes when tap on a tab during scrolling tabsView
Browse files Browse the repository at this point in the history
  • Loading branch information
charliefancelli committed Jul 16, 2014
1 parent c4877ae commit bf957b5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ICViewPager/ICViewPager/ViewPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ @interface ViewPagerController () <UIPageViewControllerDataSource, UIPageViewCon

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

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

//if Tap is not selected Tab(new Tab)
if (self.activeTabIndex != index) {
// Select the tab
[self selectTabAtIndex:index];
//if user is not scrolling Tabview
if( ! self.isScrolling ){
//if Tap is not selected Tab(new Tab)
if (self.activeTabIndex != index) {
// Select the tab
[self selectTabAtIndex:index];
}
}
}

Expand Down Expand Up @@ -747,7 +751,7 @@ - (void)defaultSettings {
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
[self addChildViewController:self.pageViewController];

// Setup some forwarding events to hijack the scrollView
// Keep a reference to the actual delegate
self.actualDelegate = ((UIScrollView *)[self.pageViewController.view.subviews objectAtIndex:0]).delegate;
Expand All @@ -759,6 +763,7 @@ - (void)defaultSettings {

self.animatingToTab = NO;
self.defaultSetupDone = NO;
self.isScrolling = NO;
}
- (void)defaultSetup {

Expand Down Expand Up @@ -875,7 +880,7 @@ - (TabView *)tabViewAtIndex:(NSUInteger)index {
}

if ([[self.tabs objectAtIndex:index] isEqual:[NSNull null]]) {

// Get view from dataSource
UIView *tabViewContent = [self.dataSource viewPager:self viewForTabAtIndex:index];
tabViewContent.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Expand Down Expand Up @@ -997,6 +1002,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
self.isScrolling = YES;
if ([self.actualDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
[self.actualDelegate scrollViewWillBeginDragging:scrollView];
}
Expand Down Expand Up @@ -1028,6 +1034,7 @@ - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
self.isScrolling = NO;
if ([self.actualDelegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
[self.actualDelegate scrollViewDidEndDecelerating:scrollView];
}
Expand Down

0 comments on commit bf957b5

Please sign in to comment.