我的应用中有以下视图层次结构:
-- 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时,它有时会触发滑动手势识别器。我无法真正看到这种模式,但这种情况经常发生。
拖动时有没有办法抑制触摸处理?
答案 0 :(得分:2)
在视图#2上使用UIPanGestureRecognizer
,而不是直接处理触摸。在两个识别器的委托中,从gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
返回NO。
OR
在UISwipeGestureRecognizer
的委托中,执行以下内容:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return gestureRecognizer.view == touch.view;
}