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

只愿长相守 提交于 2019-12-14 02:37:06

问题


I'm using UIPanGestureRecognizer on a project, and I want to take the starting point and the end point.

I tried to do for touchesBegin, but did not get a code that does what I need.

How can I get the start point and end point of the UIPanGestureRecognizer?


回答1:


For your case, you might want to include the code inside my function into your IBAction for the panGesture. Here I've created a view, but otherwise you would just be referring to self.view instead of 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)
 }

}


来源:https://stackoverflow.com/questions/34067087/get-the-start-point-and-end-point-of-the-uipangesturerecognizer-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!