我有一个奇怪的情况。我正在尝试运行动画,并且正在等待完成处理程序。一切正常,直到我定义了timingFunction。在那之后,有时completionHandler 根本不会被调用。我的动画卡在最后一帧。
CGFloat rotations = times * 2.0;
CGFloat zoomLevel = COIN_MOVE_UP;
SCNAction* rotate = [SCNAction rotateByX:M_PI_2 y:0 z:0 duration:2.0 / (rotations + 1)];
NSUInteger swaps = rotations / 2;
SCNAction* rotateSequence = [SCNAction repeatAction:rotate count:2];
SCNAction* coinRotate = [SCNAction repeatAction:rotateSequence count:swaps];
SCNAction* coinRotateAction = [SCNAction sequence:@[coinRotate, rotate]];
SCNAction* coinMoveUpAction = [SCNAction moveByX:0 y:-zoomLevel z:0 duration:1];
SCNAction* coinMoveDownAction = [SCNAction moveByX:0 y:zoomLevel z:0 duration:1];
SCNAction* coinMoveAction = [SCNAction sequence:@[coinMoveUpAction, coinMoveDownAction]];
SCNAction* coinRotateY = [SCNAction rotateByX:0 y:M_PI z:0 duration:2];
SCNAction* fullGroup = [SCNAction group:@[coinRotateAction, coinMoveAction, coinRotateY]];
[fullGroup setTimingFunction:^(float time){
return time;
}];
[self.coinNode runAction:fullGroup completionHandler:^{
// completion is not called sometimes when timingFunction is efined
}];
你知道如何解决这个问题吗?
PS我已经实现:
-(void)renderer:(id<SCNSceneRenderer>)renderer didApplyAnimationsAtTime:(NSTimeInterval)time{
}
并且没有计时功能,当动画完成时会停止调用此方法,但是当存在 timig 功能时,有时动画会一直运行到结束,但不会调用完成处理程序并且 didApplyAnimationsAtTime: 仍在被调用。所以也许这个动画在达到结束状态后仍然在运行。