【发布时间】:2014-03-29 21:49:02
【问题描述】:
我有一个正方形的CAShapeLayer,我将width 设置为2.0f。
我想为其strokeEnd 设置动画,为此我使用CABasicAnimation,如下所示:
CABasicAnimation *stroke = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
stroke.fromValue = @(0);
stroke.toValue = @(1);
stroke.repeatCount = 1;
stroke.duration = 10.0f;
stroke.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[myLayer addAnimation:stroke forKey:nil];
而且它有效。从 Matt Neuberg 的书中,我了解到我们可以通过以下方式完全省略 toValue 和 fromValue:
[CATransaction begin];
[CATransaction setDisableActions:YES];
..
..
[CATransaction commit];
然而,他的例子是基于transform。我正在尝试使用strokeEnd 来实现相同的目标。
我能做的最好的是将CATransaction 块内的strokeEnd 设置为1 或0,并相应地设置fromValue。换句话说,我似乎无法在动画strokeEnd 时同时省略toValue 和endValue - 我至少需要其中一个(即fromValue 或toValue)。
所以我的问题是,我怎样才能在完全不需要使用toValue 和fromValue 的情况下为strokeEnd 制作动画?
谢谢。
【问题讨论】:
-
属性需要改变,就这样。
-
@DavidRönnqvist 然而,这似乎不是答案的一个小提示。
-
为什么不想设置
fromValue和toValue?这让我觉得这是最直观的方法,可以精确地指定你想要为strokeEnd设置动画的对象。
标签: ios animation core-animation cabasicanimation