gpt4 book ai didi

ios - 检测长按tableview

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

我知道如何简单地检测长按,但它是在释放后检测到的。如何在不松开手指的情况下检测到长按?

这是我现在用于长按的代码:

override func viewDidLoad() {
super.viewDidLoad()
setupLongPressGesture()
}

func setupLongPressGesture() {
let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress))
longPressGesture.minimumPressDuration = 1.0 // 1 second press
longPressGesture.delegate = self
self.tableView.addGestureRecognizer(longPressGesture)
}

@objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer){
if gestureRecognizer.state == .ended {
let touchPoint = gestureRecognizer.location(in: self.tableView)
if let indexPath = tableView.indexPathForRow(at: touchPoint) {

}
}
}

最佳答案

.ended 更改为 .began

来自 UILongPressGestureRecognizer 的文档:

Long-press gestures are continuous. The gesture begins (UIGestureRecognizer.State.began) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (UIGestureRecognizer.State.ended) when any of the fingers are lifted.

关于ios - 检测长按tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52691960/

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