在不实际触摸物体的情况下移动物体 [英] moving an object without actually touching the object
问题描述
我是iPhone开发的初学者,我一直在寻找这个问题的答案,但还没有发现任何东西.
I'm a beginner when it comes to iPhone development and i've searched for the answer to this question and haven't found anything yet.
我想做的是允许用户在不实际触摸对象的情况下移动对象(他们可以触摸屏幕上的任何位置),并且随着对象的移动,对象将从原来的位置移动并沿方向移动的用户运动,但没有跳到他们的触摸位置并被他们的手指掩盖.
What i'm trying to do is allow the user to move an object without actually touching the object (they can touch anywhere on the screen) and as they move the object will go from where it was originally and move in the direction of the users movement but not jump to thier touch location and be covered up by their finger.
您能提供的任何帮助都是非凡的
Any help you can provide would be phenomenal
先谢谢您
BWC
推荐答案
您可以通过覆盖 touchBegan:withEvent:
, touchMoved:withEvent:
和 touchEnded:withEvent
消息.在这些消息中,跟踪 UITouch
对象的位置(通过使用您的 UIView
的 convertPoint:toView:
消息转换为视图上的点(重新分类)并计算运动的差异;然后将相同的差异应用于对象,无论对象位于屏幕上的何处.
You can subclass a UIView
to track the touch movements by overriding the touchBegan:withEvent:
, touchMoved:withEvent:
and touchEnded:withEvent
messages. In these messages, track the UITouch
objects' locations (converted to points on the view by using the convertPoint:toView:
message of the UIView
you're subclassing) and calculate the difference of movement; then apply the same difference to your object, wherever it might be on the screen.
这篇关于在不实际触摸物体的情况下移动物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!