重寫- (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;
}
注意對隱藏數據的判斷,之前直接粘用網上的代碼,沒有對視圖的隱藏進行判斷,導致視圖隱藏仍然可以響應點擊。