在父视图中重写hitTest方法,该方法为UIView中的方法(不可在ViewController中重写该方法)
- (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) && subView.tag == RESPOND_OUT_OF_SUPERVIEW && subView.hidden == NO) {
view = subView;
}
}
}
return view;
}
注意:重写该方法之后即使点击在SuperView之外或者父视图已经隐藏,系统也会调用该方法