【问题标题】:touchesForView in hitTesthitTest 中的 touchesForView
【发布时间】:2010-01-13 14:52:15
【问题描述】:

我有一个像容器一样使用的简单 UIView。 如果我写这段代码:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    UIView *hitView = [super hitTest:point withEvent:event];

    NSSet *sTouches = [event touchesForView:self];

    NSLog(@"Touches %d", [sTouches count] );

    return self;
}

没用!我想在 touchesBegan() 之前在 hitTest() 消息中获取触摸计数! 有可能吗?

我有这个层次结构:

UIView 
  +---> UIScrollView 

当触摸我的UIView单击)时,容器会移动。当我在UIView 上双击(两根手指)时,子UIScrollView 不适用于Zoom(例如)。 所以我有想赶上触数。

如果触摸数等于一,我的UIView 容器上的hitTest 将返回“self”。 否则,如果触摸数大于一(== 2),hitTest 返回“scrollview”指针。

换句话说,我想将两个手指事件捕获到 hitTest() 消息/事件中。

【问题讨论】:

    标签: iphone uiview touch hittest touchesmoved


    【解决方案1】:

    hitTest 被框架用来确定哪个视图被击中,从而确定将touchesBegan/touchesMoved/touchesEnded/touchesCancelled 消息发送到哪个视图。在调用hitTest 时,你无法分辨。

    也许您可以解释一下您要完成的工作,因为这似乎不是正确的方法。

    【讨论】:

    • 好的,我有这个层次结构: UIView ---> UIScrollView 当触摸我的 UIView(单击)时,容器会移动。当我双击我的 UIView 时,子 UIScrollView 不适用于 Zoom(例如)。所以我有想赶上触数。如果触摸数等于一,我的 UIView 容器上的 hitTest 返回“self”。否则,如果触摸数大于 1 (== 2),hitTest 返回“scrollview”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多