Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Window Coordinates of Touch in Gesture Recognizer in Swift?

I'm dragging a CALayer out of one UIView to another using a UIPanGestureRecognizer. In the UIGestureRecognizerState.Changed method, I am calling to move the CALayer with

var touchLocation = recognizer.locationInView(recognizer.view)
self.panForTranslation(touchLocation)

However touchLocation is returning the CALayers position relative to it's frame, not the screen coordinates.

How can I get a UITouch location of the exact point the finger is on screen?

like image 357
jwade502 Avatar asked Jun 05 '15 03:06

jwade502


1 Answers

Try this:

var touchLocation = recognizer.locationInView(recognizer.view.window)
self.panForTranslation(touchLocation)
like image 92
Bannings Avatar answered Nov 11 '22 03:11

Bannings