Skip to content

Commit

Permalink
fix crashes with pager when swiping too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
vagmi committed Aug 19, 2016
1 parent 555bdcc commit 186c19d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ICViewPager/ICViewPager/ViewPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ - (void)setActiveTabIndex:(NSUInteger)activeTabIndex {
}

- (void)setActiveContentIndex:(NSUInteger)activeContentIndex {

BOOL isTransitioning = NO;
// Get the desired viewController
UIViewController *viewController = [self viewControllerAtIndex:activeContentIndex];

Expand All @@ -392,19 +392,23 @@ - (void)setActiveContentIndex:(NSUInteger)activeContentIndex {
__weak ViewPagerController *weakSelf = self;

if (activeContentIndex == self.activeContentIndex) {


dispatch_async(dispatch_get_main_queue(), ^{
[self.pageViewController setViewControllers:@[viewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:^(BOOL completed) {
weakSelf.animatingToTab = NO;
}];
});

} else if (!(activeContentIndex + 1 == self.activeContentIndex || activeContentIndex - 1 == self.activeContentIndex)) {

dispatch_async(dispatch_get_main_queue(), ^{

[self.pageViewController setViewControllers:@[viewController]
direction:(activeContentIndex < self.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:YES
animated: NO
completion:^(BOOL completed) {

weakSelf.animatingToTab = NO;
Expand All @@ -417,15 +421,18 @@ - (void)setActiveContentIndex:(NSUInteger)activeContentIndex {
completion:nil];
});
}];
});

} else {


dispatch_async(dispatch_get_main_queue(), ^{
[self.pageViewController setViewControllers:@[viewController]
direction:(activeContentIndex < self.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:YES
animated: NO
completion:^(BOOL completed) {
weakSelf.animatingToTab = NO;
}];
});
}

// Clean out of sight contents
Expand Down

0 comments on commit 186c19d

Please sign in to comment.