- 遵守协议
<UIGestureRecognizerDelegate>
- 实现代理
recognizerRight.delegate = self;
- 实现协议里的方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// 方案1:判断触摸点是否在self.scratchedImg视图上,如果是,就设置调用的手势无效
if(CGRectContainsPoint(self.scratchedImg.frame, [touch locationInView:self.contentView])){
return NO;
}else{
return YES;
}
// 方案2:
// CGPoint point = [touch locationInView:self.view];
// CALayer *layer = [self.view.layer hitTest:point];
// if(layer == self.scratchedImg.layer) {
// return NO;
// }
// return YES;
}
注意:
1.判断触摸点是否在某一视图内,一定要放在同一坐标系下;
2.上面的self.contentView是self.scratchedImg视图的父类。
网友评论