3 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
可能最好的方法是hitTest:withEvent:在要忽略觸摸的視圖中重寫。根據(jù)視圖層次結(jié)構(gòu)的復(fù)雜性,有兩種簡(jiǎn)單的方法可以實(shí)現(xiàn)此目的。
如果在該視圖下有對(duì)該視圖的引用,則可以忽略:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
// If the hitView is THIS view, return the view that you want to receive the touch instead:
if (hitView == self) {
return otherView;
}
// Else return the hitView (as it could be one of this view's buttons):
return hitView;
}
如果您沒有對(duì)該視圖的引用:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
// If the hitView is THIS view, return nil and allow hitTest:withEvent: to
// continue traversing the hierarchy to find the underlying view.
if (hitView == self) {
return nil;
}
// Else return the hitView (as it could be one of this view's buttons):
return hitView;
}
我建議第一種方法最可靠(如果有可能獲得對(duì)基礎(chǔ)視圖的引用)。
- 3 回答
- 0 關(guān)注
- 695 瀏覽
添加回答
舉報(bào)