2015-06-05 26 views
3

我使用UIPanGestureRecognizer將CALayer從一個UIView拖出到另一個UIView。在UIGestureRecognizerState.Changed方法,我打電話與在Swift中獲取手勢識別器中的觸摸窗口座標?

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

但是touchLocation相對的CALayers位置返回到它移動的CALayer的框架,而不是屏幕座標。

如何獲取手指在屏幕上的確切點的UITouch位置?

回答

4

試試這個:

var touchLocation = recognizer.locationInView(recognizer.view.window) 
self.panForTranslation(touchLocation) 
+0

完美的作品!我很驚訝這個簡單的答案沒有發佈在我看過的同一個問題的其他問題上。 – jwade502