在父视图添加如下代码。其思路如下:
- 历父视图的所有子视图
- 判断触发事件的点是否在子视图的bounds内
- 如果在,返回这个子视图
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == nil) {
for (UIView *subView in self.subviews) {
CGPoint p = [subView convertPoint:point fromView:self];
if (CGRectContainsPoint(subView.bounds, p)) {
view = subView;
}
}
}
return view;
}