在iOS中Pan和Swipe有什么区别? [英] What is the difference between Pan and Swipe in iOS?
问题描述
听起来很简单.. 按住触控板,移动手指,释放 ..但不知何故不会触发滑动(而是触发平移)
Sounds simple .. Hold the Trackpad, move the finger, release .. But somehow swipe is not being triggered (pan is triggered instead)
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:v action:@selector(handleSwipe:)];
swipeGesture.direction= UISwipeGestureRecognizerDirectionUp;
[v addGestureRecognizer:swipeGesture];
Pan由以上序列识别。
Pan is recognized by the above sequence instead.
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:v action:@selector(handlePan:)];
[v addGestureRecognizer: panGesture];
如果评论了pan,则通过相同的手势识别滑动..有了这个,2个问题:
If pan is commented, swipe is recognized by the same gesture .. With this, 2 questions:
- 平移和滑动有什么区别?
- 如何在iPhone模拟器上模拟滑动?
- What is the difference then between a pan and a swipe?
- How can one simulate a swipe on iPhone simulator?
推荐答案
根据定义,滑动手势也必然是平移手势 - 都涉及触摸点的平移运动。不同之处在于识别器语义:平移识别器查找平移运动的开始并继续报告随时间在任何方向上的移动,而滑动识别器立即决定用户的触摸是否在所需方向上线性移动。
By definition, a swipe gesture is necessarily also a pan gesture -- both involve translational movement of touch points. The difference is in the recognizer semantics: a pan recognizer looks for the beginning of translational movement and continues to report movement in any direction over time, while a swipe recognizer makes an instantaneous decision as to whether the user's touches moved linearly in the required direction.
默认情况下,没有两个识别器会识别相同的手势,因此平移和滑动之间存在冲突。最有可能的是,你的pan识别器会赢得冲突,因为它的手势更简单/更通用:滑动是一个平移但是平移可能不是一个滑动,所以平移首先识别并排除其他识别器。
By default, no two recognizers will recognize the same gesture, so there's a conflict between pan and swipe. Most likely, your pan recognizer "wins" the conflict because its gesture is simpler / more general: A swipe is a pan but a pan may not be a swipe, so the pan recognizes first and excludes other recognizers.
您应该能够使用委托方法 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
来解决此冲突,或者通过使pan识别器依赖于滑动识别器带有 requireGestureRecognizerToFail:
。
You should be able to resolve this conflict using the delegate method gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
, or perhaps without delegation by making the pan recognizer depend on the swipe recognizer with requireGestureRecognizerToFail:
.
解决冲突后,你应该可以模拟一根手指通过快速拖动鼠标滑动。 (虽然鼠标比手指更精确,但它比在设备上做真实的东西更加挑剔。)双手平移/滑动可以通过按住Option& Shift键。
With the conflict resolved, you should be able to simulate a one-finger swipe by quickly dragging the mouse. (Though as the mouse is more precise than your finger, it's a bit more finicky than doing the real thing on a device.) Two-finger pan/swipe can be done by holding the Option & Shift keys.
这篇关于在iOS中Pan和Swipe有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!