gpt4 book ai didi

ios - UISwipeGestureRecognizer 获取开始和结束位置

转载 作者:行者123 更新时间:2023-11-28 13:27:24 28 4
gpt4 key购买 nike

在 iOS/Swift 中,UIGestureRecognizerswipinglocation 方法

determine the location where a swipe begin.

我查看了文档,但看不到如何获取滑动的开始和结束位置。我想找出开始和结束 View 中的 (x,y) 坐标。我尝试了 location(ofTouch: )ofTouch 设置了不同的值,但在模拟器中滑动时它给了我相同的值。

有办法吗?

最佳答案

您可以子类化 UISwipeGestureRecognizer 并覆盖 touchesMoved。在这里,您可以简单地存储最后一个值:

class MySwipeGestureRecognizer:UISwipeGestureRecognizer {
var lastTouches:Set<UITouch>?

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
lastTouches = touches
super.touchesMoved(touches, with:event)
}
}

然后,当手势触发时,计算 lastTouches 属性。

关于ios - UISwipeGestureRecognizer 获取开始和结束位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58112302/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com