Ios 检测tableview上的长按
我知道如何简单地检测长新闻,但它会在发布后检测。如何在不松开手指的情况下检测长按 这是我现在用于长按的代码:Ios 检测tableview上的长按,ios,swift,uitableview,uilongpressgesturerecogni,Ios,Swift,Uitableview,Uilongpressgesturerecogni,我知道如何简单地检测长新闻,但它会在发布后检测。如何在不松开手指的情况下检测长按 这是我现在用于长按的代码: override func viewDidLoad() { super.viewDidLoad() setupLongPressGesture() } func setupLongPressGesture() { let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecog
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) {
}
}
}
将
.end
更改为.start
从ui的文档中,长按GestureRecognitor
:
长时间的新闻手势是连续的。当允许的手指数(numberoftouchsrequired
)被按下指定时间(minimumPressDuration
)且触摸未超出允许的移动范围(allowableMovement
)时,手势开始(uigesturecognizer.State.begined
)。每当手指移动时,手势识别器都会转换到更改状态,当任何手指抬起时,手势识别器都会结束(uigesturecognizer.state.end
)