在 Swift 中获取 Window 手势识别器中的触摸坐标?
Get Window Coordinates of Touch in Gesture Recognizer in Swift?
我正在使用 UIPanGestureRecognizer 将 CALayer 从一个 UIView 拖到另一个。在 UIGestureRecognizerState.Changed 方法中,我调用移动 CALayer with
var touchLocation = recognizer.locationInView(recognizer.view)
self.panForTranslation(touchLocation)
但是 touchLocation 返回的是 CALayers 相对于它的框架的位置,而不是屏幕坐标。
如何获得手指在屏幕上的确切点的 UITouch 位置?
试试这个:
var touchLocation = recognizer.locationInView(recognizer.view.window)
self.panForTranslation(touchLocation)
我正在使用 UIPanGestureRecognizer 将 CALayer 从一个 UIView 拖到另一个。在 UIGestureRecognizerState.Changed 方法中,我调用移动 CALayer with
var touchLocation = recognizer.locationInView(recognizer.view)
self.panForTranslation(touchLocation)
但是 touchLocation 返回的是 CALayers 相对于它的框架的位置,而不是屏幕坐标。
如何获得手指在屏幕上的确切点的 UITouch 位置?
试试这个:
var touchLocation = recognizer.locationInView(recognizer.view.window)
self.panForTranslation(touchLocation)