I am trying to make UIView
glow back and forth twice. My animation below works but just after it has finished it goes to the state that I animated it to, and not the original. I set autoreverses to YES so why is it not going back to original state ?
[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];
The animation reverses but the value doesn't. After the animation completes it removes itself from the view (actually from the views layer) and the view appears to have the properties that have been set on it.
You could set the value back in a completion block or in the selector for the older UIView animation that you are using.
Alternatively, for animations where the value doesn't change you could benefit from using Core Animation (which doesn't hangs the value (after the animation the view goes bak to its original state)).
You would need to import QuartzCore.framework and include QuartzCore/QuartzCore.h
to get it to work.
The could would also need to be updated to something like this:
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"];