在为同级视图启用手势识别器的情况下,将 UIView 拖动到 UIScrollView 内

发布于 2024-12-15 06:17:47 字数 516 浏览 3 评论 0原文

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

-- 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 时,它有时会触发滑动手势识别器。我实在看不出其中的规律,但这种情况经常发生。

有什么办法可以抑制拖动时的触摸处理吗?

I have a following view hierarchy in my app:

-- 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).

When I start dragging view #2, it sometimes triggers the swipe gesture recognizer. I can't really see the pattern, but this happens quite often.

Is there any way to suppress the touches processing while dragging?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少跟Wǒ拽 2024-12-22 06:17:47

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

或者

UISwipeGestureRecognizer 的委托中,实现以下内容:

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

Use a UIPanGestureRecognizer on view #2 instead of handling the touches directly. In the delegate for both recognizers, return NO from gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:.

OR

In the UISwipeGestureRecognizer's delegate, implement this:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return gestureRecognizer.view == touch.view;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文