Arnaud
Arnaud

Reputation: 5112

Cancel gesture recognizer on button action

I'm working on an iPad app. I have a view in which the user can draw with his finger. This view has a subview, which is a calculator, and which have buttons.

I would like that when the user touch a button, the superview (in which the user can draw) doesn't take into account this touch. (so the user doesn't draw when he touches the calculator)

Preferably, I would like to not change the code of the calculator view and the code of my superview. I have only access to them via properties of another class.

Is there a way to solve the problem please? I have tried exclusiveTouch, but it doesn't work.

Upvotes: 0

Views: 4099

Answers (2)

anky_believeMe
anky_believeMe

Reputation: 484

Try this but include UIGestureRecognizerDelegate in your header file.

This is from apple "SimpleGestureRecognizers" example-

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{
    // Disallow recognition of tap gestures in the segmented control.
    if ((touch.view == YourButton)) 
    {
        //change it to your condition
        return NO;
    }

    return YES;
}

Upvotes: 1

Wain
Wain

Reputation: 119031

If you have access to the button action and the drawing gesture you can simply set:

gesture.enabled = NO;

To cancel the current gesture processing and / or prevent it from starting. When you want to reenable the gesture depends on what type it is and how it's used but doing it immediately (on the next line) will probably work ok.

Upvotes: 2

Related Questions