重寫- (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;
}
注意對隱藏數(shù)據(jù)的判斷会喝,之前直接粘用網(wǎng)上的代碼旬牲,沒有對視圖的隱藏進行判斷赦肋,導致視圖隱藏仍然可以響應點擊谋右。