3

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 printns 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)
codeforfood
  • 429
  • 9
  • 28

1 Answers1

2

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Yeah, but then my long press gesture recognizer interferes with my pan gesture recognizer. I'm kinda stuck between a rock and hard place. – codeforfood Apr 01 '15 at 03:18
  • @codeforfood Did you try implementing gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and returning true? – rdelmar Apr 01 '15 at 05:47
  • Yes I did, the long press works, but then whenever I scroll my long press event is fired. Keep in mind my long press is actually very short so that probably has something to do with it. – codeforfood Apr 01 '15 at 05:51
  • @codeforfood, I think you are stuck if you need the "long press" (0.06 isn't long) to be that short. A value of 0.2 worked ok for me. But the user could always pause for a bit before they try to scroll, so I'm not sure you can ever be sure the long press won't fire when the user really didn't intend that. – rdelmar Apr 01 '15 at 05:54