变更记录

序号 录入时间 录入人 备注
1 2016-04-14 Alfred Jiang -

方案名称

手势 - 判断点击位置是否在某区域 ( View ) 内

关键字

手势 \ 点击位置 \ 区域 \ UITapGestureRecognizer

需求场景

  1. 需要对手势操作的点击位置进行判断时
  2. 判断点击位置是否在某控件中时

参考链接

(无)

详细内容

判断 UITapGestureRecognizer 点击位置是否在 _viewTest 控件中

方法一:CGRectContainsPoint

1
2
3
4
5
6
- (void)touchMainViewGesture:(UITapGestureRecognizer *)gesture
{
if (CGRectContainsPoint(_viewTest.bounds, [gesture locationInView:_viewTest])) {
NSLog(@"_viewTest touched");
}
}

方法二:*- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent )event

1
2
3
4
5
6
- (void)touchMainViewGesture:(UITapGestureRecognizer *)gesture
{
if ([_viewTest pointInside:[gesture locationInView:_viewTest] withEvent:nil]) {
NSLog(@"_viewTest touched");
}
}

效果图

(无)

备注

(无)