0

First of all, I'm pretty new to swift.

I'm doing an app where I have to recognize a lot of gesture (swipe up, down, left, right, single tap, double tap, single tap with 2 fingers, double tap with 2 fingers, rotations etc etc).

I'm able to recognize each gesture, but my problem occurs when I'm doing a double tap. The app recognizes a single tap before the double tap (looks logical...), but as each gesture is dedicated to one action it's a problem: it sends the action linked to the single tap before the action linked to the double tap...

Do you have an idea how I can get rid of this ? I clearly have no idea here :/

Thank you.

Have a nice day.

// SINGLE TAP
@IBOutlet var oneFingerTap: UITapGestureRecognizer!

@IBOutlet var twoFingersTap: UITapGestureRecognizer!

// DOUBLE TAP

@IBOutlet var doubleTapOneFinger: UITapGestureRecognizer!

@IBOutlet var doubleTapTwoFinger: UITapGestureRecognizer!

// SINGLE TAP

@IBAction func oneFingerTap(_ sender: UITapGestureRecognizer) {
    statusLabel.text = "single Tap"
}

@IBAction func twoFingersTap(_ sender: UITapGestureRecognizer) {
    statusLabel.text = "Two fingers Tap"
}
// DOUBLE TAP

@IBAction func doubleTapOneFinger(_ sender: UITapGestureRecognizer) {
    statusLabel.text = "Double Tap 1 finger"
}

@IBAction func doubleTapTwoFingers(_ sender: UITapGestureRecognizer) {
    statusLabel.text = "Double Tap 2 fingers"
}

EDIT : I tried what's on [UITapGestureRecognizer - single tap and double tap

]1 but nothing's working.

Here is what I tried :

doubleTapOneFinger.require(toFail: oneFingerTap);

Doing this throw me an error "fatal error: unexpectedly found nil while unwrapping an Optional value", so I changed how I was declaring my variables to avoid using optional variables like this :

let oneFingerTap = UITapGestureRecognizer(target: self, action: #selector(self.oneFingerTap))
oneFingerTap.numberOfTapsRequired = 1
oneFingerTap.numberOfTouchesRequired = 1
self.view.addGestureRecognizer(oneFingerTap)

let twoFingerTap = UITapGestureRecognizer(target: self, action: #selector(self.twoFingersTap))
twoFingerTap.numberOfTapsRequired = 1;
twoFingerTap.numberOfTouchesRequired = 2;
self.view.addGestureRecognizer(twoFingerTap)

No more error, but nothing's happening... Do you have any idea what I can do ?

Hawkydoky
  • 194
  • 1
  • 15
  • :- Try adding this line of code [oneFingerTap requireGestureRecognizerToFail:tapRecognizerEditEffect]; – Developer Jun 12 '17 at 12:32
  • how are you creating UITapGestureRecognizer ? Is it via xib ? – Grzegorz Krukowski Jun 12 '17 at 12:42
  • 1
    Possible duplicate of [UITapGestureRecognizer - single tap and double tap](https://stackoverflow.com/questions/8876202/uitapgesturerecognizer-single-tap-and-double-tap) – Venk Jun 12 '17 at 12:52
  • @GrzegorzKrukowski yes, it's with the interface builder. I drag and drop it, and then link it with my function. – Hawkydoky Jun 12 '17 at 12:52
  • @Venkat : maybe yes, but the question itself date of 2012 and the best answer has been last edited from 2015... I think a lot of things changed since that moment :/ – Hawkydoky Jun 12 '17 at 12:58
  • 1
    @Hawkydoky there are swift 2 and swift 3 version of code. No change. Before posting the same repeated question you should try with existing answers. If its not working, then post the question with the proper reference and use case. – Venk Jun 12 '17 at 13:02
  • @Venkat : I tried almost everything I found, I guess it's something around SingleTap.require(toFail: doubleTap), but I've an EXC_BREAKPOINT on it. I can't find anything that helped me (since 1 hour) Any idea ? – Hawkydoky Jun 12 '17 at 14:34

0 Answers0