Thanks for your reply.
I'm not using Apple's gesture recognizer, I can't use them for what I need. That's why I'm overriding touchesBegan and the other, I'm doing it by myself from coordinates of gestures.
Here is a sample of what I do, maybe you'll understand better what I mean.
import UIKit
class SecondViewController: UIViewController {
//Variables definition
override func viewDidLoad() {
super.viewDidLoad()
ascending = false
UIScreen.main.wantsSoftwareDimming = true
UIScreen.main.brightness = (0.0)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.timer.invalidate()
isPinched = false
super.touchesBegan(touches, with: event)
startTime = getCurrentMillis()
for touch in touches{
let point = touch.location(in: self.view)
for (index,finger) in fingers.enumerated() {
if finger == nil {
fingers[index] = String(format: "%p", touch)
if (finger1.isEmpty){
finger1 = [point.x, point.y]
}
//And so on until finger10
break
}
}
}
//If the gesture is long enough, I have a special recognition (longPress)
timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(increaseValue), userInfo: nil, repeats: true)
if ascending {
ascending = false
}
else {
ascending = true
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
for touch in touches {
let point = touch.location(in: self.view)
for (index,finger) in fingers.enumerated() {
if let finger = finger, finger == String(format: "%p", touch) {
switch (index){
case 0 :
finger1 += [point.x, point.y]
//And so on until case 9 / finger10
default :
break
}
}
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
endTime = getCurrentMillis()
for touch in touches {
for (index,finger) in fingers.enumerated() {
if let finger = finger, finger == String(format: "%p", touch) {
fingers[index] = nil
break
}
}
}
direction[0] = ""
direction[1] = ""
direction[2] = ""
direction[3] = ""
direction[4] = ""
if finger1.count != 0 {
direction[0] = GestureRecognizer(coordinates: finger1, index: 0)
}
if finger2.count != 0 {
direction[1] = GestureRecognizer(coordinates: finger2, index: 1)
}
if finger3.count != 0 {
direction[2] = GestureRecognizer(coordinates: finger3, index: 2)
}
if finger4.count != 0 {
direction[3] = GestureRecognizer(coordinates: finger4, index: 3)
}
if finger5.count != 0 {
direction[4] = GestureRecognizer(coordinates: finger5, index: 4)
}
if Int64(endTime - startTime) < 600 {
//////////// HERE IS THE GESTURE RECOGNITION\\\\\\\\\\\\
if !finger1.isEmpty && !finger2.isEmpty && !finger3.isEmpty && !finger4.isEmpty && ((((finger1[0] <= finger3[0] + 60) && (finger1[0] >= finger3[0] - 60 )) && ((finger1[1] <= finger3[1] + 60) && (finger1[1] >= finger3[1] - 60 ))) && (((finger2[0] <= finger4[0] + 60) && (finger2[0] >= finger4[0] - 60 )) && ((finger2[1] <= finger4[1] + 60) && (finger2[1] >= finger4[1] - 60 )))) {
labelUpdate = "double tap 2 fingers"
doubleTap2()
}
else if !finger1.isEmpty && !finger2.isEmpty && !finger3.isEmpty && !finger4.isEmpty && ((((finger1[0] <= finger4[0] + 60) && (finger1[0] >= finger4[0] - 60 )) && ((finger1[1] <= finger4[1] + 60) && (finger1[1] >= finger4[1] - 60 ))) && (((finger2[0] <= finger3[0] + 60) && (finger2[0] >= finger3[0] - 60 )) && ((finger2[1] <= finger3[1] + 60) && (finger2[1] >= finger3[1] - 60 )))) {
labelUpdate = "double tap 2 fingers"
doubleTap2()
}
// and so on
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.directionLabel.text = self.labelUpdate
self.finger1 = []
self.finger2 = []
self.finger3 = []
self.finger4 = []
self.finger5 = []
self.finger6 = []
self.finger7 = []
self.finger8 = []
self.finger9 = []
self.finger10 = []
}
}
//One of the function I call
func swipeLeftTwo(){
request(urlAdress: "Url Adress")
}
func swipeRightFour(){
self.performSegue(withIdentifier: "SecondViewController", sender:self)
}
}
Is it better ?