我正在使用此代码设置对象的动画:
CGRect imageFrame = objectToAnimate.frame;
CGPoint viewOrigin;
viewOrigin.y = imageFrame.origin.y + imageFrame.size.height/2;
viewOrigin.x = imageFrame.origin.x + imageFrame.size.width/2;
objectToAnimate.layer.position = viewOrigin;
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
CGPathAddArc(curvedPath, NULL, viewOrigin.x-[radius intValue], viewOrigin.y, [radius intValue], 0, DEGREES_TO_RADIANS(115), NO);
pathAnimation.path = curvedPath;
pathAnimation.duration = 1.0f;
CGPathRelease(curvedPath);
//Animate one curve
[objectToAnimate.layer addAnimation:pathAnimation forKey:@"curvedFalling"];
一切都按预期工作。
当我再次在同一个对象上调用类似的动画时,对象会移回其原始起始位置,然后进行动画制作。我怎样才能让它从第一个动画结束后的地点开始动画?
提前非常感谢!
答案 0 :(得分:0)
objectToAnimate.frame
此处未被更改。完成动画后,您必须在此更新帧,因为它被用作下一个动画的源。要在此代码的末尾使用此代码:
.
.
.
//Animate one curve
[objectToAnimate.layer addAnimation:pathAnimation forKey:@"curvedFalling"];
objectToAnimate.frame.origin.x = viewOrigin.x;
objectToAnimate.frame.origin.y = viewOrigin.y;