简体   繁体   English

长按手势识别器仅在手指抬起时才会被触发

[英]Long Press Gesture Recognizer Only Fired When Finger is Lifted

I'm having an interesting problem with a long press gesture recognizer. 我有一个长按手势识别器的有趣问题。 I placed one of these on a UITableView, and it only works when I lift my finger after the long press. 我将其中一个放在UITableView上,只有在长按后抬起手指才会起作用。 So basically, I would place my finger on a cell, and then when I lift my finger, it triggers the long press. 所以基本上,我会把手指放在一个单元格上,然后当我抬起手指时,它会触发长按。 I figured this out by putting printn s when the long press began and ended and both fire after I lift my finger. 我通过在长按开始和结束时放置printn这个问题,并且在我抬起手指后都开火了。 I think the tableViews default panGestureRecognizer might be interfering with the longPressGestureRecognizer . 我认为tableViews默认panGestureRecognizer可能与该会干扰longPressGestureRecognizer Here is my code in viewDidLoad : 这是我在viewDidLoad代码:

    var longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
    longPress.minimumPressDuration = 0.06
    longPress.delegate = self
    self.tableView.addGestureRecognizer(longPress)
    longPress.requireGestureRecognizerToFail(self.tableView.panGestureRecognizer)

触摸单元格不会导致表格视图的panGestureRecognizer失败,因此删除requireGestureRecognizerToFail方法,然后在手指仍然按下时应该进入.Began状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM