UIGestureRecognizer - 检测点击和拖动,如触控板 [英] UIGestureRecognizer - detecting tap and drag like trackpad
问题描述
有没有办法级联UIGestureRecognizers来检测点击然后拖动。
例如,我想检测用户何时点击然后拖动他的手指。
Is there any way to cascade UIGestureRecognizers to detect a tap and then drag. For example, I want to detect when the user taps and then drags his finger around.
这类似于在触控板上拖动的方式。
This would be similar how drag works on trackpads.
所以我想检测一下水龙头,然后我想让UIPanGestureRecognizer给我发送连续更新。
So I want to detect a tap, then I want to get UIPanGestureRecognizer to send me continuous updates.
我想要使用标准的UIGesture类来创建这个新手势,而不是使用原始触摸创建我自己的手势。
I want to use standard UIGesture classes to create this new gesture instead of creating my own using raw touches.
这是否可能?
推荐答案
虽然我没有按照预期的方式找到解决方案,但我找到了更好的解决方案。
although i haven't found the solution the way i expected, i found a better solution.
仅仅使用 UILongPressGrstureRecognizer
,令人惊讶的是它能够实现点击和拖动。
By just using UILongPressGrstureRecognizer
, it is surprising that it is able to implement tap and drag.
你必须:
- 将numberOfTapsRequired设置为1以检测初始点击。
- 将minimumDuration设置得更小以更快地检测拖动无需等待
例如:
UILongPressGestureRecognizer *mouseDrag = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleDrag:)];
mouseDrag.numberOfTapsRequired=1;
mouseDrag.minimumPressDuration=0.05;
[clickLeft requireGestureRecognizerToFail:mouseDrag];
要处理拖拽,你必须确定处理它的状态作为连续手势。
to handle the drag, you must determine the state to handle it appropriately as a continuous gesture.
这篇关于UIGestureRecognizer - 检测点击和拖动,如触控板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!