I’ve implemented a repeated task on button (UIButton) hold with the code from another Stack Overflow thread ( UIButton Touch and Hold ).
For various reasons, I’d like a repeat delay. definition of repeat delay
I can’t quite wrap my head around how to do this however. I am relatively new to coding for the iPhone.
Inspired in the code you suggested you can go for something like this:
Make an
NSTimerthat will start up when the button is pressed and fire a method everyxseconds.Header (.h):
Implementation file (.m):
Make an
IBActionfor “Touch Down” to start the timer that will fire the action method every 2 seconds. Then make another IBAction for “Touch Up Inside” and “Touch Up Outside” to invalidate the timer.For example:
Then in that method fired by the
NSTimerdo whatever you need: