Dla Swift 3, na podstawie @ Andrzeja odpowiedź:
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, mój zły, że nie jest odpowiadając na pytanie, miałem ten sam problem i ktoś powiązany mi this previous answer:
Zresztą musiałem zmienić kilka rzeczy, aby to działa w szybkim 3, tutaj jest mój bieżący kod:
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
}
}
}
}
Nadal mam mały problem, ale myślę, że jest on powiązany z moim GestureRecognizer w moim kodzie. Ale to powinno wystarczyć. Wyświetli współrzędne każdego punktu w twojej konsoli.
Dziękuję za odpowiedź! Oceniłem odpowiedź giorashca jako najbardziej pomocną, ponieważ podał nieco więcej informacji, ale obie metody działają :) – Fr4nc3sc0NL
Nie ma za co! To oczywiście twoja rozmowa :) Trochę zmieniłem odpowiedź i pozostawiłem odniesienia do dokumentacji, podkreślając, jak ważne jest włączenie multi-touch lub kod nie zadziała (zawsze o tym zapominamy!). Pozostawiam tę odpowiedź jako odniesienie dla innych osób, które mogą potrzebować tego szczegółu :) – Para