许多教程存储第一次触摸的坐标,如下所示:
func panHandler(_ sender: UIPanGestureRecognizer) {
if sender.state == .began
{
originalCenter = self.center
}
}
有没有办法确切知道触摸发生在哪个位置,即在超视图的坐标系中?
答案 0 :(得分:0)
试试这个
let gestureView = sender.view
let translation: CGPoint = sender.translation(in: gestureView)
var initialCenter = gesture.location(in: sender.view
)
if sender.state == .began {
print("begin")
}
let point = CGPoint(x: CGFloat((initialCenter?.x)! + translation.x), y: CGFloat((initialCenter?.y)! + translation.y))
print(point)
答案 1 :(得分:0)
试试这个:
func panHandler(_ sender: UIPanGestureRecognizer) {
if sender.state == .began
{
print("locationOfBeganTap -> (.\(touch.locationInView(view).x - touch.translationInView(view).x), .\(touch.locationInView(view).y - touch.translationInView(view).y))")
}
}