来自 UIPanGestureRecognizer 的触摸坐标
是否可以从[UIPanGestureRecognizer TranslationInView]获取绝对触摸坐标?我正在开发一个 iPad 应用程序,并且一直在搜索大量内容以从 UIPanGestureRecognizer 获取触摸坐标值!
我也尝试过使用从 transaltionInView 获得的值进行偏移,但我真的无法理解其背后的数学......
大家有什么建议吗?
拉维
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
translationInView
是手势的增量变化。如果您将手指向左移动 20 pt,您将得到(-20.0, 0.0)
,从这个意义上来说,它已经是“绝对”了。您的意思可能是您需要
locationInView
,它相对于通过参数传递的视图,即使所述视图不是识别事件的视图。通常,您将传递视图控制器的视图,或者将处理事件的视图,或者对您的实现更有意义的子视图。另外,请记住,如果您需要真正的绝对值,您可以通过参数传递 nil,它会返回相对于窗口的值(又名“绝对”)
并且,如果您需要这样做逻辑与其他视图,您可以使用
UIView
实例方法将坐标从一个视图转换为另一个视图:convertRect:fromView:
、convertRect:toView:
,convertPoint:fromView:
、convertPoint:toView:
。这些方法还接受 nil 作为视图参数,以表示窗口的“绝对”。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 acceptnil
as the view argument to mean "absolute" to the window.这是一种更简单的方法:
返回计算为接收表示的手势给定视图中的位置的点作为 CGPoint。
Here is an easier way:
Returns the point computed as the location in a given view of the gesture represented by the receive as CGPoint.