0

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

添加手势的单元格

请帮我。提前致谢。

4

1 回答 1

0

而不是handleLongPressGetureForRow(_:)更改为self.handleLongPressGetureForRow(v:) with @objcbeforefunc

   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")
}
于 2018-02-12T08:31:59.003 回答