沿路径的动画 - 完成方法称为太早

时间:2013-03-05 22:57:04

标签: ios objective-c animation quartz-core

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

感谢这个post我想出如何使用 CAKeyframeAnimation CGMutablePathRef 来沿路径执行动画。

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];
                 }
 ];

如何在完成沿弯道的动画完成后才能触发完整的功能?

1 个答案:

答案 0 :(得分:0)

完成CAAnimation后,它会在其代理上调用animationDidStop:finished:方法。