无法同时计算两个CABasicAnimations
我正在尝试animation一个图层的strokeEnd
属性,以及另一个图层的position
。 我试图设置两个持续时间相同的CABasicAnimations,但一个比另一个更早完成。 我不能为了我的生活理解为什么。
CALayer *trackingDotPresentationLayer = (CALayer *)trackingDot.presentationLayer; CABasicAnimation *trackingDotMovementAnimation = [CABasicAnimation animationWithKeyPath:@"position"]; trackingDotMovementAnimation.duration = lineDrawDuration; trackingDotMovementAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; trackingDotMovementAnimation.fromValue = [NSValue valueWithCGPoint:trackingDotPresentationLayer.position]; trackingDot.position = futureTrackingDotFrame.origin; trackingDotMovementAnimation.toValue = [NSValue valueWithCGPoint:futureTrackingDotFrame.origin]; trackingDotMovementAnimation.fillMode = kCAFillModeForwards; [trackingDot addAnimation:trackingDotMovementAnimation forKey:@"trackingDotMovement"]; CABasicAnimation *lineAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; lineAnimation.duration = lineDrawDuration; lineAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; lineAnimation.fromValue = @0.0; lineLayer.strokeEnd = 1.0; lineAnimation.toValue = @1.0; lineAnimation.fillMode = kCAFillModeForwards; [lineLayer addAnimation:lineAnimation forKey:@"strokeEnd"];
有什么build议么?
为什么使用presentationLayer? 通常这对于任何types的animation都是不需要的。 此外,你直接设置lineLayer.strokeEnd(因此在一个隐式的animation)。 尝试删除行lineLayer.strokeEnd = 1.0;
或者,你可以像这样使用CATransaction :
lineLayer.strokeEnd = 0.0; [CATransaction begin]; [CATransaction setAnimationDuration:lineDrawDuration]; [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; trackingDot.position = futureTrackingDotFrame.origin; lineLayer.strokeEnd = 1.0; [CATransaction commit];
所以事实certificate,我的animation设置没有错。 我遇到了另一个问题,其中一个问题是在另一个问题上解决了animation问题: CALayer用对angular虚线渲染问题 。 我应该意识到,closures子path延长了animation中绘制的线条,因此造成了时间上的错误。