0

I have a UITableViewCell class where I want to detect the swipe event (delete) in order to hide some graphics drawn in the drawRect

First I added a UISwipeGestureRecognice to the cell:

// Init swipe gesture recognizer
self.swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeCell:)];
self.swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
self.swipeRecognizer.delegate = self;
[self.contentView addGestureRecognizer:self.swipeRecognizer];

Than I implemented a method to react on the swipe event:

- (void)swipeCell:(UISwipeGestureRecognizer *)recognizer
{
    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            self.swipeStartPoint = [recognizer locationInView:self.backgroundView];
            BaseLogDebug(INFO, @"Swipe Began at %@", NSStringFromCGPoint(self.swipeStartPoint));
            break;
        case UIGestureRecognizerStateChanged: {
            CGPoint currentPoint = [recognizer locationInView:self.backgroundView];
            CGFloat deltaX = currentPoint.x - self.swipeStartPoint.x;
            BaseLogDebug(INFO, @"Swipe Moved %f", deltaX);
        }
            break;
        case UIGestureRecognizerStateEnded:
            BaseLogDebug(INFO, @"Swipe Ended");
            break;
        case UIGestureRecognizerStateCancelled:
            BaseLogDebug(INFO, @"Swipe Cancelled");
            break;
        default:
            break;
    }
}

In order to allow simultaneous gesture recognizer I implemented the following method:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
 shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

The only state the gesture recognize recognizes is the state UIGestureRecognizerStateEnded. What's wrong with my code?

Morpheus78
  • 870
  • 1
  • 9
  • 21
  • possible duplicate of [detecting finger up/down UITapGestureRecognizer](http://stackoverflow.com/questions/8394256/detecting-finger-up-down-uitapgesturerecognizer) – Ty Lertwichaiworawit Aug 11 '14 at 23:19

1 Answers1

1

From the UIGestureRecognizer Class Reference docs:

Recognizers for discrete gestures transition from UIGestureRecognizerStatePossible to UIGestureRecognizerStateFailed or UIGestureRecognizerStateRecognized.

and

Gesture recognizers recognize a discrete event such as a tap or a swipe but don’t report changes within the gesture. In other words, discrete gestures don’t transition through the Began and Changed states and they can’t fail or be cancelled.

UISwipeGestureRecognizer is a discrete gesture. If you want a continuous (but similar) gesture, use a UIPanGestureRecognizer instead.

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
  • I will give it a try. Is there any other solution to receive the "lateral cell offset"? Any method to override? – Morpheus78 Aug 12 '14 at 07:08