长按手势识别器仅在手指抬起时触发 [英] Long Press Gesture Recognizer Only Fired When Finger is Lifted
问题描述
我在使用长按手势识别器时遇到了一个有趣的问题.我将其中一个放在 UITableView 上,它仅在我长按后抬起手指时才有效.所以基本上,我会将我的手指放在一个单元格上,然后当我抬起我的手指时,它会触发长按.我通过在长按开始和结束时放置 printn
来解决这个问题,并且在我抬起手指后两者都会触发.我认为 tableViews 默认的 panGestureRecognizer
可能会干扰 longPressGestureRecognizer
.这是我在 viewDidLoad
中的代码:
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. 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. I think the tableViews default panGestureRecognizer
might be interfering with the longPressGestureRecognizer
. Here is my code in 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)
推荐答案
在单元格中向下触摸不会导致 table view 的 panGestureRecognizer 失败,所以删除 requireGestureRecognizerToFail 方法,然后你应该进入 .Began 状态,同时你的手指还在.
Touching down in the cell will not cause the table view's panGestureRecognizer to fail, so delete the requireGestureRecognizerToFail method, and you should then get to the .Began state while your finger is still down.
这篇关于长按手势识别器仅在手指抬起时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!