1

我想让UIView来回发光两次。我的动画在下面的作品中,但在它结束之后,它会转到我将其设置为动画的状态,而不是原作。我将autoreverses设置为YES,为什么它不回到原始状态?UIView动画不会回到原始状态

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationRepeatCount:2]; 
[UIView setAnimationRepeatAutoreverses:YES]; 
[UIView setAnimationDuration:0.3]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
textDetailView.layer.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.3].CGColor; 
[UIView commitAnimations]; 

回答

1

动画反转,但值不。动画完成后,它将从视图中删除(实际上是从视图图层中删除),并且该视图似乎具有已设置的属性。

您可以将值设置回完成块或选择器中,以便使用旧版UIView动画。

或者,对于值不变的动画,您可以使用核心动画(不会挂起该值(在动画之后视图变为原始状态))中获益。

您需要导入QuartzCore.framework并包含QuartzCore/QuartzCore.h才能使其运行。

的也需要进行更新,以这样的事:

CABasicAnimation *myColorAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; 
[myColorAnimation setAutoreverses:YES]; 
[myColorAnimation setRepeatCount:2]; 
[myColorAnimation setDuration:0.3]; 
[myColorAnimation setToValue:(id)[myColor CGColor]]; 
// the default "from value" is the current value 
[[textDetailView layer] addAnimation:myColorAnimation forKey:@"myColorKey"]; 
+0

我使用CABasicAnimation直到我意识到我需要使用“didFinishSelector”做我的动画完成后的东西。由于我被迫回到这个问题,我如何得到一个信号表明我的CABasicAnimation已经完成了?是否有某种委托方法?谢谢 – pnizzle

+0

@pnizzle在这个特定的情况下,你不需要回调,因为视图在动画之后会有原始的颜色,就像你想要的那样。这就是为什么它适合你的情况。 –

+1

@pnizzle是的,您可以将自己设置为动画的'委托',然后您将获得'animationDidStart:'和'animationDidStop:已完成:' –