- (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)recognizer { CGFloat translationX = [recognizer translationInView:self.slidingViewController.view].x; CGFloat velocityX = [recognizer velocityInView:self.slidingViewController.view].x; switch (recognizer.state) { case UIGestureRecognizerStateBegan: { BOOL isMovingRight = velocityX > 0; if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionCentered && isMovingRight) { [self.slidingViewController anchorTopViewToRightAnimated:YES]; } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionCentered && !isMovingRight) { [self.slidingViewController anchorTopViewToLeftAnimated:YES]; } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionAnchoredLeft) { [self.slidingViewController resetTopViewAnimated:YES]; } else if (self.slidingViewController.currentTopViewPosition == ECSlidingViewControllerTopViewPositionAnchoredRight) { [self.slidingViewController resetTopViewAnimated:YES]; } break; } case UIGestureRecognizerStateChanged: { if (!self.positiveLeftToRight) translationX = translationX * -1.0; CGFloat percentComplete = (translationX / self.fullWidth); if (percentComplete < 0) percentComplete = 0; [self updateInteractiveTransition:percentComplete]; break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled: { BOOL isPanningRight = velocityX > 0; if (self.coordinatorInteractionEnded) self.coordinatorInteractionEnded((id)self.slidingViewController); if (isPanningRight && self.positiveLeftToRight) { [self finishInteractiveTransition]; } else if (isPanningRight && !self.positiveLeftToRight) { [self cancelInteractiveTransition]; } else if (!isPanningRight && self.positiveLeftToRight) { [self cancelInteractiveTransition]; } else if (!isPanningRight && !self.positiveLeftToRight) { [self finishInteractiveTransition]; } break; } default: break; } }