响应视图外点击范围的子试图

重写- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event,返回你想响应的点击视图

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event {

UIView*view = [super hitTest:pointwith Event:event];

if(view ==nil) {

for(UIView*subView in self.subviews) {

CGPoint tp = [subView convertPoint:pointfromView:self];

if(CGRectContainsPoint(subView.bounds, tp) && !subView.hidden) {

view = subView;

}

}

}

returnview;

}

注意对隐藏数据的判断,之前直接粘用网上的代码,没有对视图的隐藏进行判断,导致视图隐藏仍然可以响应点击。

你可能感兴趣的:(响应视图外点击范围的子试图)