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

标签 ios swift

在 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/

相关文章:

iOS 1D/2D条码扫描器库

ios - 如何使用 View Controller (swift)重新加载 TableView

ios - 如何在另一个函数中创建 sender.tag UIButton?

ios - 在 Swift 的图像查看区中看不到图像

ios - sqlite3_last_insert_rowid 在第一次插入后返回 0

ios - xcode中倒计时器的继承

ios - 归档 CocoaPods 依赖项以发布到 App Store 时出错

iphone - 无法删除节中的行

ios - 任意取整

ios - 启动 Watchkit 扩展时出错