我尝试做一个 CAKeyFrameAnimation 来旋转图层:
CALayer* theLayer = myView.layer;
CAKeyframeAnimation* animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 1.0;
animation.cumulative = NO;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0 * M_PI],
[NSNumber numberWithFloat:0.5 * M_PI],
[NSNumber numberWithFloat:0.3 * M_PI], // animation stops here...
[NSNumber numberWithFloat:0.8 * M_PI], // ignored!
[NSNumber numberWithFloat:0.7 * M_PI], nil]; // ignored!
animation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.2],
[NSNumber numberWithFloat:2.0], // ignored!
[NSNumber numberWithFloat:1.5], // ignored!
[NSNumber numberWithFloat:2], 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"];
就像您在评论中看到的那样,动画只运行两个关键帧,但不是全部。无论我在那里输入什么样的值,动画都不会运行超过两个关键帧。
那里可能有什么问题?