My view has a toolbar with two buttons of type UIBarButtonItem
. I'm trying to implement a gesture recognizer such that when I tap anywhere in the view except in the toolbar, I call a selector. Tapping on a bar button item in the toolbar should call that button's action method. The view conforms to the UIGestureRecognizerDelegate
protocol and implements the shouldReceiveTouch
method as follows:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *) touch {
// Disallow recognition of tap gestures in the toolbar
if ((touch.view == self.sideOneBarButton.customView) &&
(gestureRecognizer == self.tapRecognizer)) {
return NO;
}
return YES;
}
The problem is, when I tap on the toolbar button, touch.view
is of type UTToolbarTextButton*
which is an undocumented class, so my if statement fails and the shouldReceiveTouch
always returns YES and my button event never gets called.
Ideally, I'd like to say: if the touch is anywhere in the toolbar, then return no. What's the best way to do this?