iOS touchesBegan判断点击在哪个view中
2017-06-15 本文已影响32人
e5311f1a36e5
简单说明:
- 通过判断当前点击的point是否在某个view的layer中来判断点击是在哪个view中
代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGPoint point = [[touches anyObject] locationInView:self.view];
point = [self.subView1.layer convertPoint:point fromLayer:self.view.layer];
if ([self.subView1.layer containsPoint:point]) {
//处理点击到这个view中要执行的事件
return;
}
}