3

我有以下视图结构

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;
}
4

1 回答 1

3

[super hitTest:point withEvent:event]在适当的时候打电话怎么样?

于 2012-06-07T12:40:47.750 回答