[英]UISwipeGestureRecognizer to obtain start and end location
In iOS/Swift the UIGestureRecognizer
for swiping has location
methods that在 iOS/Swift 中,用于 滑动的
UIGestureRecognizer
具有location
方法
determine the location where a swipe begin.
确定滑动开始的位置。
I have looked through the doc but I cannot see how to obtain both the start and end location of the swipe.我查看了文档,但看不到如何获取滑动的开始和结束位置。 I would like to figure out the (x,y) coordinates within the view of both the start and end.
我想找出开始和结束视图中的 (x,y) 坐标。 I tried
location(ofTouch: )
with different values for ofTouch
but that gives me the same value when swiping in the simulator.我尝试了使用不同的
ofTouch
值的location(ofTouch: )
,但是在模拟器中滑动时这给了我相同的值。
Is there a way to do it?有没有办法做到这一点?
You could subclass UISwipeGestureRecognizer
and override touchesMoved
.您可以
UISwipeGestureRecognizer
并覆盖touchesMoved
。 Here, you can simply store the last value:在这里,您可以简单地存储最后一个值:
class MySwipeGestureRecognizer:UISwipeGestureRecognizer {
var lastTouches:Set<UITouch>?
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
lastTouches = touches
super.touchesMoved(touches, with:event)
}
}
Then, when the gesture fires, evaluate the lastTouches
property.然后,当手势触发时,评估
lastTouches
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.