I have a gesture recognizer that is interfering with `UIButton`s being pushed. I found a thread at http://stackoverflow.com/questions/3344341/uibutton-inside-a-view-that-has-a-uitapgesturerecognizer which suggested two solutions. One solution was to add `tap.cancelsTouchesInView = false;` to my code but this did nothing. Someone on that thread said that this only works when the view that contains the gesture is a sibling of a `UIControl`. My gesture is in a class called `ChessBoard` that is a subview of `UIView`. A `UILabel` is a subview of `ChessBoard` and the `UIButton` is a subview of that `UILabel`. So the view is a grandparent of the `UIControl` so this solution will not work.
The other solution is to add code like the following:
I added the following code to my program in the `ChessBoard` class:
However, it still does not work. The `NSLog` always says that `touch.view` is `ChessBoard`, even when the `UIButton` is being pushed. I don't understand is how the program determines what `touch.view' is.
The other solution is to add code like the following:
Code:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UIControl class]]) {
// we touched a button, slider, or other UIControl
return NO; // ignore the touch
}
return YES; // handle the touch
}
I added the following code to my program in the `ChessBoard` class:
Code:
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(@"%@", NSStringFromClass([touch.view class]));
if([touch.view isKindOfClass:[UIButton class]]) {
return false;
}
else {
return true;
}
}
However, it still does not work. The `NSLog` always says that `touch.view` is `ChessBoard`, even when the `UIButton` is being pushed. I don't understand is how the program determines what `touch.view' is.