Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touch Coordinates from UIPanGestureRecognizer

Is it possible to get the absolute touch coordinates from [UIPanGestureRecognizer translationInView]? I'm working on an iPad app and have been searching a lot to get the touch coordinate values from UIPanGestureRecognizer!

I've also tried offsetting using the values we get from transaltionInView but I'm not really able to comprehend the math behind it...

Any suggestions guys?

Ravi

like image 365
Ravi Avatar asked Aug 25 '11 20:08

Ravi


1 Answers

translationInView is the delta change of a gesture. If you move your finger to the left by 20 pt, you'll get (-20.0, 0.0), it's already "absolute" in that sense.

What you probably mean is that you want the locationInView, which relative to the view handed through the argument, even if said view is not the one recognizing the events. Typically, you would hand the view of the view controller, or the view that will take care of the event, or the subview which makes more sense to your implementation.

Also, keep in mind, if you need the real absolute, you can hand nil through the arguments, and it returns it relative to the window (aka. "absolute")

And, if you need to do logic with other views, you can convert the coordinate from one view to another with the UIView instance methods: convertRect:fromView:, convertRect:toView:, convertPoint:fromView:, convertPoint:toView:. These methods also accept nil as the view argument to mean "absolute" to the window.

like image 84
Can Avatar answered Oct 18 '22 02:10

Can