我正在尝试为一个图层的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"];
有什么建议吗?
答案 0 :(得分:0)
您为什么使用presentationLayer?通常,任何类型的动画都不需要这样。此外,您直接设置lineLayer.strokeEnd(因此在隐式动画中)。尝试删除行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];
答案 1 :(得分:0)
事实证明,我的动画设置没有任何问题。我有另一个问题,其中一个被动画的对象在另一个问题中解决了:CALayer rendering issues with diagonal dashed line。我应该已经意识到关闭子路径是扩展动画中绘制的线,因此导致看起来不正确的时间。