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 ?