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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With