0

I'm seeing some weird behavior from long press gestures in swift. The minimum duration of the long press is 1 second. If I press for a smidgen over 1 second then the long press is detected. But if I press for 2 or more seconds, it is not detected. What is going on? Is there some maximum pres time I must worry about? Can I change this?

Marc
  • 3,386
  • 8
  • 44
  • 68

2 Answers2

0

the long press gesture recognizer has some default numbers built in. For example you can configure 'NumberOfTapsRequire', 'numberOfTouchesRequired', 'minimumPressDuration'...etc.

Also, gesture recognizer has different states like .Failed, .Began, .Changed.

So by default, the longPressGesuture does fail after sometime because it's default time was exceeded.

so in your case it could have been read as canceled.

Continuous gesture recognized but later cancelled:

.Possible -> .Began -> .Changed (repeatedly) -> .Cancelled

whereisleo
  • 818
  • 5
  • 12
0

Ok, my bad. It actually wasn't my code, I had to debug someone else's. Turns out that there is a background thread talking to a server to get updated info, and that thread keeps trying to update the interface every second. So, a long press starts on a view, but by the time one second has passed, it is a different view so the long press never completes on that view! Obviously I changed the code, so it only updates a view if something about it actually changes. Now it only rarely has to change the view, so long presses work fine.

Marc
  • 3,386
  • 8
  • 44
  • 68