拖动手势识别器干扰滑动手势识别器(Drag Gesture Recognizer interfere with swipe Gesture Recognizer)

编程入门 行业动态 更新时间:2024-10-24 12:22:15
拖动手势识别器干扰滑动手势识别器(Drag Gesture Recognizer interfere with swipe Gesture Recognizer)

我有关于手势识别器的问题。 我在视图中有两个手势识别器,一个添加到背景超级视图中以滑动以更改背景颜色,另一个添加到可拖动的子视图中。

问题是拖动手势受到滑动的干扰。 当我拖动视图时,在某些情况下,拖动操作将被识别为滑动并触发滑动操作。 我不想要这个,我只想在完成这个拖动操作后才能识别滑动。 当我快速拖动子视图时,更常见这种情况。 每次拖动过程中,都会触发滑动操作。

I have a problem about gesture recognizer. I have two gesture recognizers in my view, one added to the background superview to swipe to change background color, the other one is added to a subview which could be dragged around.

The problem is the drag gesture is interfered with the swipe. When I drag the view around, in some case, drag operation will be recognized as a swipe and trigger the swipe operation. I don't want this, I just want swipe could be recognized after finish this drag operation. This situation is more often when I drag the subview around quickly. Every time during the drag, the swipe operation will be triggered.

最满意答案

您需要使用requireGestureRecognizerToFail:设置较小的UIGestureRecognizer requireGestureRecognizerToFail:并传递您想要对其重要的识别器。

UIView *subview = .... [self addSubview:subview]; [self.gestureRecognizer requireGestureRecognizerToFail:subview.gestureRecognizer];

You need to setup your lesser UIGestureRecognizer with requireGestureRecognizerToFail: and pass your recognizer that you want to be important to it.

UIView *subview = .... [self addSubview:subview]; [self.gestureRecognizer requireGestureRecognizerToFail:subview.gestureRecognizer];

更多推荐

本文发布于:2023-07-16 07:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125446.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:手势   拖动   干扰   Drag   swipe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!