Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel/reset an UIGestureRecognizer

how can I cancel or reset an UIGestureRecognizer? The problem is, that if I set waitForSomething to NO during a gesture, the next event is UIGestureRecognizerStateChanged. But the first event should be UIGestureRecognizerStateBegan.

My Code:

- (void) panned:(UIPanGestureRecognizer *) recognizer {
    if (waitForSomething) {
        // cancel or reset the recognizer!
        // because the next event should be UIGestureRecognizerStateBegan and not UIGestureRecognizerStateChanged
        return;
    }

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            // important initialisation code
            break;

        case UIGestureRecognizerStateChanged:
            // do something
            break;
    }
}

Thank you for you help!

like image 876
Manni Avatar asked Jul 06 '11 08:07

Manni


1 Answers

I got it! :-)

Maybe someone else runs in this problem, here is the solution:

if (waitForSomething) {
    recognizer.enabled = NO;
    recognizer.enabled = YES;
    return;
}

The next event will be UIGestureRecognizerStateFailed followed by UIGestureRecognizerStateBegan.

like image 56
Manni Avatar answered Oct 12 '22 23:10

Manni