This question already has an answer here:
- Drag UIView around Shape Comprised of CGMutablePaths 1 answer
I have a UIBezierPath (curved like an '8', with only 4 points in it) and I need to make some kind of CGPoint-Array out of it. Any ideas? thanx!
edit:
I have my bezier initlialized like that
-(void) initBezier
{
theBezierPath = [UIBezierPath bezierPath];
[theBezierPath moveToPoint:P(211.00, 31.00)];
[theBezierPath addCurveToPoint:P(870.00, 191.00) controlPoint1:P(432.00, -11.00) controlPoint2:P(593.00, 209.00)];
[theBezierPath addCurveToPoint:P(731.00, 28.00) controlPoint1:P(1061.95, 178.53) controlPoint2:P(944.69, 5.78)];
[theBezierPath addCurveToPoint:P(189.00, 190.00) controlPoint1:P(529.00, 49.00) controlPoint2:P(450.00, 189.00)];
[theBezierPath addCurveToPoint:P(211.00, 31.00) controlPoint1:P(-33.01, 190.85) controlPoint2:P(71.00, 37.00)];
}
and I animate an object on it with
anim = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
anim.path = theBezierPath.CGPath;
anim.calculationMode = kCAAnimationCubicPaced;
anim.repeatCount = HUGE_VALF;
anim.duration = tme;
I want to animate the object on the path pixel by pixel (via touch-position). I want the object to "snap" a given coordinate of a touch to the nearest point on the curve so it touch-slides the object along the path.