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 UIPa开发者_如何学GonGestureRecognizer!
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.
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.
精彩评论