Advertisement
undeadhip

Untitled

Dec 10th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NSUInteger selectedIndex = [self.navigationView indexOfSelectedButton];
  2.  
  3.     BOOL directionRight = index > selectedIndex;
  4.  
  5.     UIViewController *currentController = self.viewControllers[selectedIndex];
  6.     UIViewController *targetController = self.viewControllers[index];
  7.  
  8.     NSArray *allControllers = self.viewControllers;
  9.     if (directionRight) {
  10.         self.viewControllers = @[currentController, targetController];
  11.     } else {
  12.         self.viewControllers = @[targetController, currentController];
  13.     }
  14.  
  15.     [self.collectionView reloadData];
  16.  
  17.     NSIndexPath *indexPath = [NSIndexPath indexPathForItem:!directionRight inSection:0];
  18.     [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
  19.     [self.collectionView layoutIfNeeded];
  20.  
  21.     self.collectionViewAnimationFinishBlock = ^{
  22.         self.collectionView.userInteractionEnabled = YES;
  23.         self.viewControllers = allControllers;
  24.         [self.collectionView reloadData];
  25.  
  26.         NSUInteger realIndexForTargetController = [self.viewControllers indexOfObject:targetController];
  27.         NSIndexPath *realIndexPath = [NSIndexPath indexPathForItem:realIndexForTargetController inSection:0];
  28.         [self.collectionView scrollToItemAtIndexPath:realIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
  29.  
  30.         [self.navigationView setSelectedIndex:selectedIndex];
  31.         UIViewController *controller = self.viewControllers[index];
  32.         [self configureNavigationBarForController:controller];
  33.     };
  34.  
  35.     self.collectionView.userInteractionEnabled = NO;
  36.     indexPath = [NSIndexPath indexPathForItem:directionRight inSection:0];
  37.     [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement