0
我想沿圓形路徑實現動畫,並在動畫結束後立即觸發完成功能。沿路徑動畫 - 完成方法調用太早
由於這個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];
}
];
只有在沿着彎曲路徑的動畫完成後,我如何才能激發完整的功能?