0

Is there any way that i can setup a tapGestureRecognizer in an iOS app, that either sends a signal both when an object is tapped, and when the tap is released, or setup up two tapGestureRecognizer's, one that handles the tap, and one that handles the release?

My tapGestureRecognizer is initialized like this:

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(TapInToSubView))
    tapRecognizer.numberOfTapsRequired = 1

    sender.addGestureRecognizer(tapRecognizer)

Hope someone out there can help!

Anthony
  • 33
  • 6
  • http://stackoverflow.com/questions/15628133/uitapgesturerecognizer-make-it-work-on-touch-down-not-touch-up – David Feb 01 '17 at 20:33
  • 1
    A Tap is a tap. You are probably looking for UIGestureRecognizer state .began, .changed, .ended. – Leo Dabus Feb 01 '17 at 20:34

1 Answers1

1

You need to set up a UILongPressGestureRecognizer . Set the minimumPressDuration and You can then handle the gesture state methods :

(sender.state == UIGestureRecognizerStateEnded)
(sender.state == UIGestureRecognizerStateBegan

etc. and fire your actions accordingly.

Long-press gestures are continuous. The gesture begins (began) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (ended) when any of the fingers are lifted.

  • @LeoDabus Why not ? If you have a better solution, post it . –  Feb 01 '17 at 20:43
  • UIGestureRecognizer would be enough for what the OP is asking – Leo Dabus Feb 01 '17 at 20:44
  • @LeoDabus UILongPressGestureRecognizer is a subclass of UIGestureRecognizer and does not make a difference. However, having it as a UILongPressGestureRecognizer you can set up multiple different recognizers on the same view and make it more clean and easy. You can for example still add a UITapGestureRecognizer simulataniously. If you think this does not answer the question or is not a solution/good solution, You can add your UIGestureRecognizer as an answer and the OP and readers will have multiple choises to chose from. –  Feb 01 '17 at 20:49
  • @LeoDabus This solves the question and still allows a tapGesture to be added simultaniously if needed without any mess. As I said, a UILongPressGestureRecognizer is a SUBCLASS of UIGestureRecognizer. If you want to post your methods with UIGestureRecognizer do it, so people can see the different options and upvote yours instead!! –  Feb 01 '17 at 20:56
  • "BTW the minimum time OP would have to wait is 0.5 sec", this is the DEFAULT VALUE. NOT THE MINIMUM. the MINIMUM VALUE is 0. –  Feb 01 '17 at 20:58