Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you program a Continuous Delete Button?

I'm making a calculator app and am supplying my own keypad with UIButtons. I have a delete key and everything works except that the user has to keep pressing the delete key over and over again if they want to delete all.

I was wondering if there is a way to delete everything when the button is held for more than 2 seconds.

like image 288
OnkaPlonka Avatar asked Mar 16 '13 08:03

OnkaPlonka


3 Answers

The simplest way of implementing this would be attaching a long press gesture recognizer to your [Delete] button.

Xcode lets you attach long press gesture recognizer in the interface builder. Add it to your button, configure the duration of long press, and connect the handler to IBOutlet in the same way that you connect other UI events.

If you would rather do it in code, this answer shows you how.

like image 144
Sergey Kalinichenko Avatar answered Oct 17 '22 21:10

Sergey Kalinichenko


Use your own timer function to handle this

-(IBAction)buttonHit {
    //here start timer that fires for every 2 seconds and handle deletion method in that
}

-(IBAction)buttonReleased {
   //Stop timer...
}
like image 32
Guru Avatar answered Oct 17 '22 21:10

Guru


In your subclassed UIButton, you might want to watch the "touchesBegan: withEvent:" UIResponder method and if it passes a certain threshold of time, then start deleting like crazy (that is, until the "touchesEnded: withEvent" method gets called).

like image 1
Michael Dautermann Avatar answered Oct 17 '22 20:10

Michael Dautermann