3 回答
TA贡献1786条经验 获得超13个赞
可能最好的方法是hitTest:withEvent:在要忽略触摸的视图中重写。根据视图层次结构的复杂性,有两种简单的方法可以实现此目的。
如果在该视图下有对该视图的引用,则可以忽略:
- (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;
}
如果您没有对该视图的引用:
- (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;
}
我建议第一种方法最可靠(如果有可能获得对基础视图的引用)。
- 3 回答
- 0 关注
- 658 浏览
添加回答
举报