CAKeyFrameAnimation 中的 keyTime 是什么样的值?
例如,我有这个 CAKeyFrameAnimation:
CALayer* theLayer = myView.layer;
CAKeyframeAnimation* animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 1.6;
//animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0 * M_PI],
[NSNumber numberWithFloat:(15.0/180.0) * M_PI],
[NSNumber numberWithFloat:(30.0/180.0) * M_PI], // animation stops here...
[NSNumber numberWithFloat:(45.0/180.0) * M_PI], // ignored!
[NSNumber numberWithFloat:(190.0/180.0) * M_PI], nil]; // ignored!
animation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.4], // ignored!
[NSNumber numberWithFloat:0.8], // ignored!
[NSNumber numberWithFloat:1.6], nil]; // ignored!
animation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], nil];
[theLayer addAnimation:animation forKey:@"transform.rotation.z"];
我不明白的是:
A)关键时间值是自动画开始以来的绝对经过时间吗?
B) 关键时间值只是说明该特定关键帧要使用多少时间?
For example I have this CAKeyFrameAnimation:
CALayer* theLayer = myView.layer;
CAKeyframeAnimation* animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 1.6;
//animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0 * M_PI],
[NSNumber numberWithFloat:(15.0/180.0) * M_PI],
[NSNumber numberWithFloat:(30.0/180.0) * M_PI], // animation stops here...
[NSNumber numberWithFloat:(45.0/180.0) * M_PI], // ignored!
[NSNumber numberWithFloat:(190.0/180.0) * M_PI], nil]; // ignored!
animation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:0.4], // ignored!
[NSNumber numberWithFloat:0.8], // ignored!
[NSNumber numberWithFloat:1.6], nil]; // ignored!
animation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], nil];
[theLayer addAnimation:animation forKey:@"transform.rotation.z"];
What I don't get is:
A) are key time values absolute passed time since the animation has started?
B) are key time values just saying how much time to use for this particular key frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
docs 这里的措辞有点奇怪,但很准确:
基本上,每个值都指示给定关键帧发生在动画中的哪个标准化点。因此,如果关键帧占动画的 25%,则该值将为 0.25。文档中令人困惑的部分是它们表明这是一个持续时间,而实际上它是一个标准化的时间点。
The docs are phrased a little oddly here, but are accurate:
Basically, each value indicates at what normalized point in the animation the given keyframe occurs. So if a keyframe is 25% into the animation, the value would be 0.25. The confusing part of the docs is they indicate that it is a duration, when in fact it's a normalized point in time.
keyTimes 的值是总持续时间的百分比。有效值范围为 0 到 1(0% 到 100%)。您最后的值 1.6 无效。
举个例子,如果一个关键帧应该发生在动画的 0.8 秒处,那么在持续时间为 1.6 秒的情况下,keyTime 将为 0.5。
The value of keyTimes is a percent of the total duration. Valid values range between 0 and 1 (0% to 100%). Your last value of 1.6 is invalid.
As an example, if a keyframe is supposed to happen 0.8 seconds into the animation that keyTime would be 0.5 given your duration of 1.6 seconds.