我有以下视图结构
UIView(1)
|--> UIScrollView
|-----------> UIView(2)
|------> UIButton
UIView(1)中的hitTest已被以下内容覆盖:
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * vv = [[self subviews] objectAtIndex:0];
if ([vv pointInside:point withEvent:event])
{
UIView *rv = [vv hitTest:point withEvent:event];
return rv;
}
if ([self pointInside:point withEvent:event])
{
return vv;
}
return nil;
}
这是为了捕捉 UIScrollView 在滚动视图本身之外拖动所必需的。
问题是,当单击UIButton时,附加到它的事件不会触发。从 hitTest 返回的视图是 UIView(2)。
如何让 UIButton 响应点击事件?
修改 在建议 Mundi 之后,我用以下内容交换了hitTest并且它有效。当然,我忘了叫[super hitTest:]。
- (UIView *)hitTest:(CGPoint) point withEvent:(UIEvent *)event
{
/* this view should have only view only: the scroll view */
UIView * scrv = [self findScrollView];
UIView *superView = [super hitTest:point withEvent:event];
if (superView == self)
{
return scrv;
}
return superView;
}
答案 0 :(得分:3)
如何在适当的时候调用[super hitTest:point withEvent:event]
?