0

I have an UILongPressGestureRecognizer on UIButton. My gesture recogniser has minimum duration of 0.5 seconds. When I press and hold it I want it to fire every 0.5 seconds I press. How can I do it?

Nikita Zernov
  • 5,465
  • 6
  • 39
  • 70

2 Answers2

1

You can't do it with a gesture. You would need to implement the underlying touch management methods from UIControl and track the touches begin and end (and use your own timer). Once the gesture has fired it needs to end and be started again by a new touch.

I suppose it should be possible to create your own gesture which does it as you then have access to the touches, though I'm not sure how the system would react to your repeated state changes...

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Not really, there's usually little cause yo do it. Perhaps a custom gesture tutorial even if you don't acyullay create a gesture, it's just about the methods you use really – Wain May 05 '15 at 19:33
1

For each touch event you will get below callbacks on corresponding view/viewcontroller.

touchesBegan:withEvent:, 
touchesMoved:withEvent:, 
touchesEnded:withEvent:, and 
touchesCancelled:withEvent:

Simple way to implement this is to, fire a timer in touchesBegan:withEvent callback method, and invalidate the timer in touchesEnded:withEvent and touchesCancelled:withEvent methods.

You can use a simple UIView also for this, no need to go for a new UIControl or GestureRecognizer, if you are looking for a simple solution.

Trident
  • 810
  • 9
  • 20