For Swift 3, based on @Andrew's answer:
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. I had a bad one that did not answer your question, had the same problem, and someone connected me with this previous answer :
In any case, I had to change a few things to make it work in swift 3, here is my current code:
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 } } } }
I still have a little problem, but I think this is due to my GestureRecognizer in my code. But that should do the trick. It will print you the coordinates of each point in the console.
source share