iPhone - 沿触摸和拖动路径移动对象 [英] iPhone - Move object along touch and drag path
问题描述
我正在开发一个简单的动画,其中 UIImageView
沿 UIBezierPath
移动,现在我想提供用户交互移动 UIImageView
,以便用户可以通过触摸 UIImageView $来指导
UIImageView
c $ c>并在屏幕上拖动 UIImageview
。
I am developing a simple animation where an UIImageView
moves along a UIBezierPath
, now I want to provide user interation to the moving UIImageView
so that user can guide the UIImageView
by touching the UIImageView
and drag the UIImageview
around the screen.
推荐答案
因此,您希望用户能够沿着弯曲路径触摸关键帧动画中间的图像,并将其拖动到其他位置?你想在那个时候想要发生什么?
So you want the user to be able to touch an image in the middle of a keyframe animation along a curved path, and drag it to a different location? What do you want to happen to the animation at that point?
你有多重挑战。
首先是在关键帧动画处于飞行中时检测对象上的触摸。
First is detecting the touch on the object while a keyframe animation is "in flight".
为此,您需要使用父视图的图层的表示层的hitTest方法。
To do that, you want to use the parent view's layer's presentation layer's hitTest method.
图层的表示层表示任何给定时刻图层的状态,包括动画。
A layer's presentation layer represents the state of the layer at any given instant, including animations.
一旦检测到触摸在您的视图中,您需要从表示层获取图像的当前位置,停止动画,并使用基于touchesMoved / touchesDragged的动画接管。
Once you detect touches on your view, you will need to get the image's current location from the presentation layer, stop the animation, and take over with a touchesMoved/touchesDragged based animation.
我写的一个演示应用程序,演示如何检测沿路径设置动画的对象的触摸。这将是一个很好的起点。
I wrote a demo application that shows how to detect touches on an object that's being animated along a path. That would be a good starting point.
看看这里:
这篇关于iPhone - 沿触摸和拖动路径移动对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!