Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arubinst

macrumors 6502
Original poster
May 26, 2008
328
189
Lausanne - Switzerland
Hi,

I need a button to respond in the following way. When the user presses and releases, an action is executed. When the user presses this same button, but keeps pressing, the same action is executed repeatedly until the button is finally released.

Any ideas how to do this?

Thanks in advance,

Arubinst
 

tyr2

macrumors 6502a
May 6, 2006
833
242
Leeds, UK
You could use an NSTimer that checks the state of the button when it fires, if it is still active then it executes the relevant code again?
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
You need a timer. Bind an action to the "Touch Down Inside" event of the button which turns on the timer. Bind an action to "Touch up Inside" which turns off the timer.

You may need to bind a few more of the buttons events to the timer turn off method. In case the the user touches the buttons, then drags outside and lets up for instance.
 

arubinst

macrumors 6502
Original poster
May 26, 2008
328
189
Lausanne - Switzerland
Thank you guys. The timer seems to be the way to go! I got it working but now I want to take this to the next level.

I'm now trying to combine two timers (one fires the other), so that simply pressing the button and releasing makes one thing happen but keeping the button pressed for more than a second starts the cyclic repetition of an event.

I've never used NSTimers before, so this is a nice exercise. Again, thanks for your help.

Edit: I got it running the way I wanted it!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.