【发布时间】:2013-03-17 21:36:10
【问题描述】:
我有一个名为parentView 的视图,它有一个名为childView 的子视图。 childView 的一部分在parentView 的范围之外,childView 附加了一个panGestureRecognizer。我在parentView 中实现了以下内容,以便它能够识别对childView 的触摸,即使它超出了它的超级视图范围:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0)
{
for (UIView *subview in self.subviews)
{
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil)
{
return result;
break;
}
}
}
return [super hitTest:point withEvent:event];
}
然而,当我触摸或拖动childView 时,hitTest 甚至不会在parentView 上被调用。这是为什么呢?
【问题讨论】:
标签: iphone ios cocoa-touch uiview hittest