1

I just made a simple app to try out any type of gestures. I got to the tap gesture. So I thought, what if I made a fast tap game kind of application that counts the amount of taps the user performed. But soon enough I ran into some issues.

It did not count all the taps. If I began to tap as fast as possible, but it skipped taps.

The idea is I programmatically created a view in the superview and added a tapGestureRecognizer on the view. And simply put the “taps” into a label in the app.

It seems to fail to receive a system gesture on time.

The code:

let tap = UITapGestureRecognizer(target: self, action: #selector(tapped(sender:)));
    tap.numberOfTapsRequired = 1;
    animationView.isUserInteractionEnabled = true;
    animationView.addGestureRecognizer(tap);

The function:

@objc func tapped (sender :UITapGestureRecognizer) {
   self.counter += 1;
   self.lblScore.text = String(self.counter);
}

I have an animationView that I made "tappable" and it works. Every time I tap the animationView it increments the value of 'counter' that works! but every time I get this error if I tap too fast:

<_UISystemGestureGateGestureRecognizer: 0x1c01c4b00>: Gesture: Failed to receive system gesture state notification before next touch
halfer
  • 19,824
  • 17
  • 99
  • 186
Arabig
  • 21
  • 1
  • 4
  • What have you tried? Please post relevant code... – Xcoder Jan 18 '18 at 22:18
  • I edited my post, the codes are in the post now. I hope you get the idea now.. Thanks in advance! – Arabig Jan 18 '18 at 22:42
  • Welcome to Stack Overflow! This looks like a good question. You have code, a detailed description, and an error. Minor pro-tip: if you can avoid lols, chatty material and please-help-me pleading, that will make your questions even better. We like succinct here! – halfer Jan 18 '18 at 23:36
  • 2
    @halfer sorry, i will keep that in mind next time! Thank you – Arabig Jan 18 '18 at 23:38

1 Answers1

0

Create Gesture :

let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
panGesture.delegate = self
Button.addGestureRecognizer(panGesture)

let longTapGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongTapGesture(_:)))
Button.addGestureRecognizer(longTapGesture)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
Button.addGestureRecognizer(tapGesture)

let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selector(handleRotateGesture(_:)))
rotateGesture.delegate = self
Button.addGestureRecognizer(rotateGesture)

let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
pinchGesture.delegate = self
Button.addGestureRecognizer(pinchGesture)    

Gesture click Event :

extension AddTextVC: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

    @IBAction func handlePanGesture(_ recognizer: UIPanGestureRecognizer) {

    }

    @IBAction func handlePinchGesture(_ recognizer: UIPinchGestureRecognizer) {

    }

    @IBAction func handleRotateGesture(_ recognizer: UIRotationGestureRecognizer) 
    {

    }

    @IBAction func handleTapGesture(_ recognizer: UITapGestureRecognizer) {

    }

    @IBAction func handleLongTapGesture(_ recognizer: UITapGestureRecognizer) {

    }
}
P.J.Radadiya
  • 1,493
  • 1
  • 12
  • 21