Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何删除动画(CABasicAnimation)?_Iphone_Cocoa_Core Animation - Fatal编程技术网

Iphone 如何删除动画(CABasicAnimation)?

Iphone 如何删除动画(CABasicAnimation)?,iphone,cocoa,core-animation,Iphone,Cocoa,Core Animation,我想在动画(CABasicAnimation)完成之前将其删除 例如: 在我的代码中,我开始将针从旋转值0设置为目标值5。当指针达到旋转值3时,如何停止动画 CALayer* layer = someView.layer; CABasicAnimation* animation; animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.fromValue = [NSNumber

我想在动画(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"];
更改:

animation.toValue = [NSNumber numberWithFloat:5];


通过查看CALayer上的presentationLayer属性,可以监视转换的当前值。表示层在动画中保存当前值

即:

要在3处停止动画,我将抓取该层,删除0-5动画,使用presentationLayer中的fromValue和toValue 3开始一个新动画。设置动画的持续时间取决于动画的行为,但如果希望动画在3停止时需要3/5秒才能完成,则可以通过查看动画在0-5之间的距离来确定动画的距离,然后从3/5秒中减去,得到你想要使用的剩余时间

在iPhone会议上,我从Marcus Zarra那里学到了很多关于CoreAnimation的知识。我建议你关注他的博客,买他的书

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

layer.removeAnimation(forKey: "bounce")
还有

layer.removeAllAnimations()

请格式化您的代码。现在应该更清晰了。请注意,
transform.rotation.z
的这些值可能不会达到您期望的效果
transform.rotation.z
以弧度为单位,其中2π=一个圆。因此,值为5将使指针绕一个圆圈,因为一个完整的圆圈将是6.28…。同样地,3几乎是一个半圆(确切地说,半圆就是π=3.14…)。如果你要重新格式化代码,为什么不同时修改拼写呢?好的。我还修正了问题中的英语。我猜他的意思是有条件地在3点停止动画。如果你想突然停止动画,这是一个很好的答案。
[layer removeAnimationForKey:@"transform.rotation.z"];

layer.removeAnimation(forKey: "bounce")
layer.removeAllAnimations()