获取 Swift 中 UIPanGestureRecognizer 的起点和终点

Get the start point and end point of the UIPanGestureRecognizer in Swift

我在一个项目上使用UIPanGestureRecognizer,我想取起点和终点。

我尝试为 touchesBegin 做,但没有得到满足我需要的代码。

如何获取UIPanGestureRecognizer的起点和终点?

对于您的情况,您可能希望将我函数中的代码包含到 panGesture 的 IBAction 中。在这里我创建了一个视图,否则你将只引用 self.view 而不是 view.

var view = UIView()

func panGestureMoveAround(gesture: UIPanGestureRecognizer) {

 var locationOfBeganTap: CGPoint

 var locationOfEndTap: CGPoint

 if gesture.state == UIGestureRecognizerState.Began {

     locationOfBeganTap = gesture.locationInView(view)

 } else if gesture.state == UIGestureRecognizerState.Ended {

    locationOfEndTap = gesture.locationInView(view)
 }

}