获取Swift中UIPanGestureRecognizer的起点和终点

时间:2015-12-03 13:18:03

标签: swift swift2 uipangesturerecognizer swift2.1

我在项目中使用UIPanGestureRecognizer,我想采取起点和终点。

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

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

1 个答案:

答案 0 :(得分:6)

对于您的情况,您可能希望将我的函数中的代码包含在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)
 }

}