// point:是方法調(diào)用者坐標(biāo)系上的觸摸點(diǎn)的位置
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// 1.判斷下能否接收觸摸事件
if (self.userInteractionEnabled == NO || self.hidden == YES || self.alpha <= 0.0 ) return nil;
// 2.判斷下點(diǎn)在不在控件上
if ([self pointInside:point withEvent:event] == NO) return nil;
// 3.從后往前遍歷子控件
int count = ( int )self.subviews.count;
for ( int i = count - 1 ; i >= 0 ; i--) {
// 取出顯示在最前面的子控件
UIView *childView = self.subviews[i];
// 轉(zhuǎn)換成子控件坐標(biāo)系上點(diǎn)
CGPoint childP = [self convertPoint:point toView:childView];
UIView *fitView = [childView hitTest:childP withEvent:event];
if (fitView) {
return fitView;
}
}
// 表示沒有比自己更合適的view
return self; }
|