如何删除动画(CABasicAnimation)?

3 iphone cocoa core-animation

我想在完成之前删除动画(CABasicAnimation).

例如:

在我的代码中,我从一个旋转值0到目标值5开始设置动画针.当针达到旋转值3时,如何停止动画?

CALayer* layer = someView.layer;
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0];
animation.toValue = [NSNumber numberWithFloat:5];
animation.duration = 1.0;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[layer addAnimation:rotationAnimation forKey:@"transform.rotation.z"];
Run Code Online (Sandbox Code Playgroud)

RSM*_*RSM 9

[layer removeAnimationForKey:@"transform.rotation.z"];

layer.removeAnimation(forKey: "bounce")
Run Code Online (Sandbox Code Playgroud)

还有

layer.removeAllAnimations()
Run Code Online (Sandbox Code Playgroud)


AlB*_*lue 1

改变:

animation.toValue = [NSNumber numberWithFloat:5];
Run Code Online (Sandbox Code Playgroud)

animation.toValue = [NSNumber numberWithFloat:3];
Run Code Online (Sandbox Code Playgroud)