iamDonMokong
iamDonMokong

Reputation: 27

Cancel UIGestureRecognizer when a button is tapped?

Is it possible to cancel a UIGestureRecognizer when I tap on a button?

Upvotes: 2

Views: 757

Answers (3)

Arthur
Arthur

Reputation: 1760

Yes you can. You can add it and remove, by this code.

-(IBAction) YourButtonAction {
  some code, that your button must to do
  self.yourButton removeGestureRecognizer: (yourRecognizer);
}

Upvotes: 0

Satheesh
Satheesh

Reputation: 11276

Try this method :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

return whateverYouWant;
} 

Upvotes: 0

Mani
Mani

Reputation: 571

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    // test if our control subview is on-screen
    if([gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]]){
        if ([touch.view isKindOfClass:[UIButton class]]) {
            return NO; // ignore the touch
        }
    }
    return YES; // handle the touch
}

Upvotes: 9

Related Questions