开发者

How to move an UIView along a curved CGPath according to user dragging the view

I'm trying to build a interface that the user can move his finger around the screen an a list of images moves along a path. The idea is that the images center nevers leaves de path.

Most of the things I found was about how to animate using CGPath and not about actually using the path as the track to a user movement.

== Update. Better description ==

I need to objects to be tracked on the path even if the user isn't moving his fingers over the path.

For example (image bellow), if the object is at the beginning of the path and the user touches anywhere on the screen and moves his fingers from left to right I need that the object moves from left to right but following the path, that is, going up as it goes to the right towards the path's end.

== End update

This is the path I've draw, imagine that I'll have a view (any image) that the user can touch and drag it along the path, there's no need to move the finger exactly over the path. If the user move from left to right the image should move from left to right but going up if need following the path.

开发者_如何学Python

How to move an UIView along a curved CGPath according to user dragging the view

This is how I'm creating the path:

   CGPoint endPointUp = CGPointMake(315, 124);
    CGPoint endPointDown = CGPointMake(0, 403);
    CGPoint controlPoint1 = CGPointMake(133, 187);
    CGPoint controlPoint2 = CGPointMake(174, 318);

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, endPointUp.x, endPointUp.y);
    CGPathAddCurveToPoint(path, NULL, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPointDown.x, endPointDown.y);

Any idead how can I achieve this?


You can take a mathematical function that draws a graph, and then move along this trajectory
object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜