0

I am using a long press gesture recognizer because without it if I click and release quickly on the buttons, the code doesn't execute properly. But with the long press gesture recognizer, my buttonUp function does not execute. How can I check if a finger is off the screen using long press gesture recognizer?

AjinkyaSharma
  • 1,870
  • 1
  • 16
  • 26
Popolok11
  • 57
  • 9

2 Answers2

0

You may refer to this if you want to have release action and hold down action in your button!

OR

You can check on the state of gesture in your long press here!

OR

Handling a long-press gesture from Apple Developer Documentation

Hope it helps. Cheers.

Anthony FSS
  • 50
  • 1
  • 10
0

If you want to perform any action with a single tap and long press you can add gestures into button this way:

 @IBOutlet weak var btn: UIButton!

override func viewDidLoad() {

    let tapGesture = UITapGestureRecognizer(target: self, #selector (tap))  //Tap function will call when user tap on button
    let longGesture = UILongPressGestureRecognizer(target: self, #selector(long))  //Long function will call when user long press on button.
    tapGesture.numberOfTapsRequired = 1
    btn.addGestureRecognizer(tapGesture)
    btn.addGestureRecognizer(longGesture)
}

@objc func tap() {

    print("Tap happend")
}

@objc func long() {

    print("Long press")
}

This way you can add multiple methods for a single button and you just need Outlet for that button for that.

Vimalkumar N.M.
  • 493
  • 2
  • 4
  • 16
  • I needed a function to be called when the button gets released/untapped. The tapped thing is working fine. – Popolok11 Apr 01 '19 at 22:53