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];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With