Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening to UITouch event along with UIGestureRecognizer

I am creating a custom UIView and adding a UITapGestureRecognizer on it. I have a handler for the tap gesture. But at the same time I want my UIView to listen to touchesBegan & touchesEnded methods. I have implemented gestureRecognizer:shouldReceiveTouch: method also but touchesBegan/touchesEnded methods does not get called. Any clue why?

Inside my custom UIView

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)iGestureRecognizer shouldReceiveTouch:(UITouch *)iTouch {
    return YES;
}

Inside my view controller

MyCustomView aCustomView = [[[MyCustomView alloc] init] autorelease];
                UIGestureRecognizer *myGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[aCustomView addGestureRecognizer:myGestureRecognizer];
                [myGestureRecognizer release];
like image 761
Abhinav Avatar asked Mar 20 '12 00:03

Abhinav


1 Answers

You need to set cancelsTouchesInView (and likely delaysTouchesBegan and delaysTouchesEnded) to NO for the gesture recognizer. The default behavior of a gesture recognizer is to avoid having both it and the view process the touch. These settings let you fine-tune that behavior.

like image 186
Rob Napier Avatar answered Oct 27 '22 01:10

Rob Napier