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

Fix crashes when tap on a tab during scrolling tabsView #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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