LongPressGesture不能长时间按压运动

LongPressGesture不能长时间按压运动

我正在尝试将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

请帮我。提前致谢。

最佳答案

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 - LongPressGesture不能长时间按压运动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48742103/

10-11 14:59