通常是在UIGestureRecognizer的代理函数中进行操作
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
两种思路:
- 根据touch的view的类型进行判断
//example
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//如果点击视图为uitableview 则忽略手势
// NSLog(@"view class:%@",[touch.view class]);
if([touch.view isKindOfClass:[UITableView class]]){
return NO;
}
return YES;
}
- 根据touch点击point是否在目标view的frame中
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//注意:_touchView应该是_referenceView的子视图
CGPoint p = [touch locationInView:_referenceView];
//NSLog(@"frame:%@",NSStringFromCGPoint(p));
if(CGRectContainsPoint (_touchView.frame, p)){
return NO;
}
return YES; }
两种思路,一般来说第二种适用性更广,尤其面对比较复杂的视图构成的情况。