沿着bezier路径拖动UIView

时间:2012-10-14 18:31:11

标签: ios animation uiview

我需要将UIView沿着bezier路径从一个点拖到另一个点,最好的方法是什么?

1 个答案:

答案 0 :(得分:2)

这是将uiview从一个点拖动到另一个点的最简单方法。

UIBezierPath *path  = [UIBezierPath bezierPath];
[path moveToPoint:startingPoint];
[path addLineToPoint:endPoint]; //you can use addCurveToPoint: , addArcToPoint:, etc

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 10.0;
pathAnimation.path = path;
pathAnimation.removeOnCompletion = NO ;
[myView.layer addAnimation:pathAnimation forKey:@"pathAnimation"];