UILongPressGesture工作不是长按

时间:2018-02-12 08:23:15

标签: ios swift uigesturerecognizer uilongpressgesturerecogni

我试图将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

Cells where adding gesture

请帮帮我。提前谢谢。

1 个答案:

答案 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")
}