Ravi
Ravi

Reputation: 8309

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

Upvotes: 10

Views: 11670

Answers (2)

Esqarrouth
Esqarrouth

Reputation: 39201

Here is an easier way:

gesture.locationInView(myView)

Returns the point computed as the location in a given view of the gesture represented by the receive as CGPoint.

Upvotes: 0

Can
Can

Reputation: 8581

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.

Upvotes: 18

Related Questions