[英]iOS - completion block in UIView animateWithDuration gets called too early
[英]Animation along path - Completion method called too early
我想沿圓角路徑實現動畫,並在動畫結束后立即觸發完成函數。
由於這個職位我想通了如何使用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添加到animations塊中,就具有與完成塊立即執行相同的結果。
[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];
}
];
僅在完成沿彎曲路徑的動畫播放后,如何才能觸發完整功能?
完成CAAnimation
后,它將在其委托上調用animationDidStop:finished:
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.