hitTest: withEvent:方法
- 事件傳遞的時(shí)候調(diào)用
- 當(dāng)事件傳遞給控件的時(shí)候,就會(huì)調(diào)用控件的這個(gè)方法佩研,去尋找最合適的view
- 作用:尋找最合適的view
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// 調(diào)用系統(tǒng)的做法去尋找最合適的view匣掸,返回最合適的view
UIView *fitView = [super hitTest:point withEvent:event];
return fitView;
}
pointInside:withEvent:方法
- 作用:判斷當(dāng)前這個(gè)點(diǎn)在不在方法調(diào)用者(控件)上
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return YES;
}
使用場(chǎng)景
- 經(jīng)常使用的:當(dāng)兩個(gè)控件有重疊霸琴,需要將事件判斷是哪一個(gè)控件執(zhí)行的時(shí)候
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// 當(dāng)前坐標(biāo)系上的點(diǎn)轉(zhuǎn)換到按鈕上的點(diǎn)
CGPoint btnF = [self.btn convertPoint:point fromView:self];
// 判斷點(diǎn)在不在按鈕上
if ([self.btn pointInside:btnF withEvent:event]) {
// 點(diǎn)在按鈕上
return self.btn;
}else{
return [super hitTest:point withEvent:event];
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者