例如,我有以下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)关键时间值仅表示该特定关键帧要使用多少时间?
最佳答案
docs在这里有点奇怪,但很准确:
基本上,每个值都指示给定关键帧出现在动画的哪个标准化点。因此,如果关键帧占动画的25%,则该值为0.25。文档中令人困惑的部分是它们指示持续时间,而实际上这是标准化的时间点。
关于iphone - CAKeyFrameAnimation中的keyTime是什么样的值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2184803/