Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSUInteger selectedIndex = [self.navigationView indexOfSelectedButton];
- BOOL directionRight = index > selectedIndex;
- UIViewController *currentController = self.viewControllers[selectedIndex];
- UIViewController *targetController = self.viewControllers[index];
- NSArray *allControllers = self.viewControllers;
- if (directionRight) {
- self.viewControllers = @[currentController, targetController];
- } else {
- self.viewControllers = @[targetController, currentController];
- }
- [self.collectionView reloadData];
- NSIndexPath *indexPath = [NSIndexPath indexPathForItem:!directionRight inSection:0];
- [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
- [self.collectionView layoutIfNeeded];
- self.collectionViewAnimationFinishBlock = ^{
- self.collectionView.userInteractionEnabled = YES;
- self.viewControllers = allControllers;
- [self.collectionView reloadData];
- NSUInteger realIndexForTargetController = [self.viewControllers indexOfObject:targetController];
- NSIndexPath *realIndexPath = [NSIndexPath indexPathForItem:realIndexForTargetController inSection:0];
- [self.collectionView scrollToItemAtIndexPath:realIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
- [self.navigationView setSelectedIndex:selectedIndex];
- UIViewController *controller = self.viewControllers[index];
- [self configureNavigationBarForController:controller];
- };
- self.collectionView.userInteractionEnabled = NO;
- indexPath = [NSIndexPath indexPathForItem:directionRight inSection:0];
- [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement