Advertisement
redribben

panning

Feb 16th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)recognizer {
  2.     CGFloat translationX  = [recognizer translationInView:self.slidingViewController.view].x;
  3.     CGFloat velocityX     = [recognizer velocityInView:self.slidingViewController.view].x;
  4.  
  5.     switch (recognizer.state) {
  6.         case UIGestureRecognizerStateBegan: {
  7.             BOOL isMovingRight = velocityX > 0;
  8.  
  9.             if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionCentered && isMovingRight) {
  10.                 [self.slidingViewController anchorTopViewToRightAnimated:YES];
  11.             } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionCentered && !isMovingRight) {
  12.                 [self.slidingViewController anchorTopViewToLeftAnimated:YES];
  13.             } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionAnchoredLeft) {
  14.                 [self.slidingViewController resetTopViewAnimated:YES];
  15.             } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionAnchoredRight) {
  16.                 [self.slidingViewController resetTopViewAnimated:YES];
  17.             }
  18.            
  19.             break;
  20.         }
  21.         case UIGestureRecognizerStateChanged: {
  22.             if (!self.positiveLeftToRight) translationX = translationX * -1.0;
  23.             CGFloat percentComplete = (translationX / self.fullWidth);
  24.             if (percentComplete < 0) percentComplete = 0;
  25.             [self updateInteractiveTransition:percentComplete];
  26.             break;
  27.         }
  28.         case UIGestureRecognizerStateEnded:
  29.         case UIGestureRecognizerStateCancelled: {
  30.             BOOL isPanningRight = velocityX > 0;
  31.            
  32.             if (self.coordinatorInteractionEnded) self.coordinatorInteractionEnded((id<UIViewControllerTransitionCoordinatorContext>)self.slidingViewController);
  33.            
  34.             if (isPanningRight && self.positiveLeftToRight) {
  35.                 [self finishInteractiveTransition];
  36.             } else if (isPanningRight && !self.positiveLeftToRight) {
  37.                 [self cancelInteractiveTransition];
  38.             } else if (!isPanningRight && self.positiveLeftToRight) {
  39.                 [self cancelInteractiveTransition];
  40.             } else if (!isPanningRight && !self.positiveLeftToRight) {
  41.                 [self finishInteractiveTransition];
  42.             }
  43.            
  44.             break;
  45.         }
  46.         default:
  47.             break;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement