我试图将UILongPressGesture添加到单元格中。它正在工作,但只有当我长按并向任何方向移动时。 它应该在长按时调用选择器方法,但是当我长按并开始移动时它正在调用。我也处理手势的状态,但选择器没有打电话,直到我长按并开始移动。
我也尝试过向手机内容视图及其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
请帮帮我。提前谢谢。
答案 0 :(得分:0)
而不是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")
}