在UIScrollView中拖动UIView,并为兄弟视图启用手势识别器

时间:2011-11-14 22:49:33

标签: iphone objective-c cocoa-touch uigesturerecognizer

我的应用中有以下视图层次结构:

-- UIScrollView (canCancelContentTouches is NO)
   -- UIView #1 (UISwipeGestureRecognizer is bound to it to track horizontal swipes)
      -- UIView #2 (touchesBegan/touchesMoved/touchesEnded are implemented here to allow
                    dragging this view inside its parent; implementation is very
                    straightforward and I'm NOT calling supermethods here).

当我开始拖动视图#2时,它有时会触发滑动手势识别器。我无法真正看到这种模式,但这种情况经常发生。

拖动时有没有办法抑制触摸处理?

1 个答案:

答案 0 :(得分:2)

在视图#2上使用UIPanGestureRecognizer,而不是直接处理触摸。在两个识别器的委托中,从gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:返回NO。

OR

UISwipeGestureRecognizer的委托中,执行以下内容:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return gestureRecognizer.view == touch.view;
}