Per Swift 3, sulla base di @ risposta di Andrew:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touchSet = touches
for touch in touchSet{
let location = touch.location(in: self.view)
print(location)
}
}
EDIT, il mio male, che non è rispondere alla tua domanda, ha avuto lo stesso problema e qualcuno mi ha legato a this previous answer:
Comunque, ho dovuto cambiare alcune cose per rendere funziona in rapida 3, ecco il mio codice corrente:
var fingers = [String?](repeating: nil, count:5)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
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)
print("finger \(index+1): x=\(point.x) , y=\(point.y)")
break
}
}
}
}
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) {
print("finger \(index+1): x=\(point.x) , y=\(point.y)")
break
}
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
for touch in touches {
for (index,finger) in fingers.enumerated() {
if let finger = finger, finger == String(format: "%p", touch) {
fingers[index] = nil
break
}
}
}
}
Ho ancora un piccolo problema ma penso che sia collegato al mio GestureRecognizer nel mio codice. Ma quello dovrebbe fare il trucco. Ti stamperà le coordinate di ogni punto nella tua console.
Grazie per la risposta! Ho segnato la risposta di giorashc come più utile perché mi ha dato qualche informazione in più, ma entrambi i metodi funzionano :) – Fr4nc3sc0NL
Prego! Ovviamente è la tua chiamata :) Ho modificato la risposta un po 'e ho lasciato riferimenti alla documentazione, sottolineando come sia importante abilitare il multi-touch o il codice non funzionerà (ci dimentichiamo sempre!). Sto lasciando questa risposta come riferimento per le altre persone che potrebbero aver bisogno di quel dettaglio :) – Para