0

I try to create UIButton, which will increase some variable with long-pressing. So, when user touch button for long time increasing handler repeats.

I have something like this:

Swift 4.0

@IBOutlet var increaseButton: UIButton!
var someVariable = 0

...

increaseButton.addTarget(self, action: #selector(increase(sender:)), for: .touchUpInside)

...

@IBAction func increase(sender: UIButton) {
    someVariable += 1
}

Thanks for all answers!

Golovanov Dmytrii
  • 527
  • 1
  • 6
  • 20

1 Answers1

0

You can use combination of three different control events for button mainly,

.touchDown
.touchUpOutside
.touchUpInside

And track the time between touchDown and any touchup events to change your handler time.

Sandeep
  • 20,908
  • 7
  • 66
  • 106