A tips for testing existence of subviews
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
// Disallow tapRecognizer for btn touched
return !(touch.view == _categoriesBtn || // DISALLOW CATEGORIES BOTTOM MENU AND ITS BUTTONS
touch.view == _categories1Btn ||
touch.view == _categories2Btn ||
touch.view == _categories3Btn ||
touch.view == _myMenuView || // DISALLOW RIGHT MENU AND ITS BUTTONS
touch.view == _myMenuView.menu1Btn ||
touch.view == _myMenuView.menu2Btn ||
touch.view == _myMenuView.menu3Btn ||
touch.view == _myMenuView.menu4Btn ||
touch.view == _myMenuView.menu5Btn ||
touch.view == _myMenuView.menu6Btn ||
开发者_StackOverflow社区 touch.view == _myMenuView.menu7Btn);
}
return YES;
}
Regards,
KL94If you have a pointer to a view containing all of the buttons, you can use this code to see if the tap is on a button in that view.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
UIView *sview; //This is the superview containing the buttons
if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
return !([touch.view isKindOfClass:[UIButton class]] && [touch.view isDescendentOfView:sview]);
return YES;
}
How about defining a set:
NSSet *views=[NSSet setWithObjects: _categoriesBtn, _categories1Btn, /*list your views here*/ ,nil];
Then test like this
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
// Disallow tapRecognizer for btn touched
return ![views containsObject:touch.view]
}
精彩评论