gpt4 book ai didi

ios - ONLongPressGesture 作用于移动而不是长按

转载 作者:行者123 更新时间:2023-11-30 11:46:46 29 4
gpt4 key购买 nike

我正在尝试将 UILongPressGesture 添加到单元格中。它有效,但仅当我长按并向任何方向移动时才有效。它应该在长按时调用选择器方法,但当我长按并开始移动时它会调用。我也在处理手势的状态,但选择器不会调用,直到我长按并开始移动。

我也尝试过向单元格的内容 View 及其 UIlable 元素添加手势,但没有成功。

let longPressGesture: UILongPressGestureRecognizer = {
let gesture = UILongPressGestureRecognizer()
gesture.addTarget(self, action: #selector(MyViewController.handleLongPressGetureForRow(_:)))
gesture.delaysTouchesBegan = false
gesture.cancelsTouchesInView = false
gesture.numberOfTouchesRequired = 1
gesture.minimumPressDuration = 0.2
return gesture
}()
cell.addGestureRecognizer(longPressGesture)
cell.tag = indexPath.row

Cells where adding gesture

请帮助我。提前致谢。

最佳答案

而不是 handleLongPressGetureForRow(_:)更改为 self.handleLongPressGetureForRow(v:)@objc之前func

   let longPressGesture: UILongPressGestureRecognizer = {
let gesture = UILongPressGestureRecognizer()
gesture.addTarget(self, action: #selector(self.handleLongPressGetureForRow(v:)))
gesture.delaysTouchesBegan = false
gesture.cancelsTouchesInView = false
gesture.numberOfTouchesRequired = 1
gesture.minimumPressDuration = 0.2
return gesture
}()
cell.addGestureRecognizer(longPressGesture)
cell.tag = indexPath.row

return cell
}
@objc func handleLongPressGetureForRow(v: UILongPressGestureRecognizer )
{
print("saghsaghghsgfsgsaghghsaghsaghghsaghashgsasa")
}

关于ios - ONLongPressGesture 作用于移动而不是长按,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48742103/

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