3

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?

James
  • 1,167
  • 1
  • 13
  • 37
  • http://stackoverflow.com/a/13270442/1801544 ? – Larme Dec 03 '15 at 13:21
  • @Larme I am new in programming for iOS, and Swift started in two months. I still can not understand well the Objective-C. You could post an example in Swift? – James Dec 03 '15 at 13:23

1 Answers1

10

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)
 }

}
Dieblitzen
  • 544
  • 4
  • 22
  • 1
    I have a use case where the location at Began time doesn't really tell me the starting point, especially if I put down the finger (normal speed), then pan quickly. Seems like the pan gesture records the location only when it fires, i.e. probably after another gesture recognizer like "tap" failed. – Arcank Jun 05 '18 at 23:23
  • Well, here is the answer: https://stackoverflow.com/a/6950812/255585. The Began state can have a non 0,0 translation, so it needs to be substracted from the Began position to get the real starting point. – Arcank Jun 06 '18 at 01:15