SWCellScrollView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // SWCellScrollView.m
  3. // SWTableViewCell
  4. //
  5. // Created by Matt Bowman on 11/27/13.
  6. // Copyright (c) 2013 Chris Wendel. All rights reserved.
  7. //
  8. #import "SWCellScrollView.h"
  9. @implementation SWCellScrollView
  10. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  11. {
  12. if (gestureRecognizer == self.panGestureRecognizer) {
  13. CGPoint translation = [(UIPanGestureRecognizer*)gestureRecognizer translationInView:gestureRecognizer.view];
  14. return fabs(translation.y) <= fabs(translation.x);
  15. } else {
  16. return YES;
  17. }
  18. }
  19. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  20. // Find out if the user is actively scrolling the tableView of which this is a member.
  21. // If they are, return NO, and don't let the gesture recognizers work simultaneously.
  22. //
  23. // This works very well in maintaining user expectations while still allowing for the user to
  24. // scroll the cell sideways when that is their true intent.
  25. if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
  26. // Find the current scrolling velocity in that view, in the Y direction.
  27. CGFloat yVelocity = [(UIPanGestureRecognizer*)gestureRecognizer velocityInView:gestureRecognizer.view].y;
  28. // Return YES iff the user is not actively scrolling up.
  29. return fabs(yVelocity) <= 0.25;
  30. }
  31. return YES;
  32. }
  33. @end