0

我想沿圆形路径实现动画,并在动画结束后立即触发完成功能。

感谢这篇文章,我想出了如何使用CAKeyframeAnimationCGMutablePathRef沿路径执行动画。

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 1.0;

CGPoint endPoint = CGPointMake(self.boardReference.view.bounds.size.width/2,self.boardReference.view.bounds.size.height/2);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, self.view.center.x, self.view.center.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, self.view.center.y, endPoint.x, self.view.center.y, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
[self.view.layer addAnimation:pathAnimation forKey:@"curvedPath"];

[self addNewCardAtPoint:endPoint]; //This should only be launched after the animation has been finished

问题:我的方法addNewCardAtPoint只能在动画完成后调用。目前该过程没有阻塞,因此该方法或多或少同时被调用。

在第一个视图中, animateWithDuration 函数似乎更适合,因为它为动画和完成动作定义了块。但是简单的将 CAKeyframeAnimation 添加到动画块中,结果基本相同,立即执行完成块。

[UIView animateWithDuration:0.8
                 animations:^{
                     NSLog(@"-Animate on curved path to end point-");
                     ... //how perform the same path based animation here?
                 } completion:^(BOOL finished) {
                     [self addNewCardAtPoint:self.view.center];
                 }
 ];

只有在沿着弯曲路径的动画完成后,如何才能触发完整的功能?

4

1 回答 1

0

当 aCAAnimation完成时,它将调用animationDidStop:finished:其委托上的方法。

于 2013-03-05T23:20:57.233 回答