2013-03-05 38 views
0

我想沿圆形路径实现动画,并在动画结束后立即触发完成功能。沿路径动画 - 完成方法调用太早

由于这个post我想出如何使用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]; 
       } 
]; 

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

回答

0

CAAnimation完成后,它将在其委托上调用animationDidStop:finished:方法。