This code is being executed in the touchesended method of a subclassed uiview, however it doesn’t animate, it just instantly changes the background color. What is wrong?
self.backgroundColor = [UIColor blackColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:20];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
if (score < .40) {
self.backgroundColor = [UIColor redColor];
} else {
self.backgroundColor = [UIColor greenColor];
}
[UIView commitAnimations];
The
[UIView commitAnimations]method isn’t blocking – so if you call it, it will start animating, but it will execute code after this point instantly. If you have any code below it that changes the background color, it will break your animations.If that doesn’t work, try animating a different property – I know off the top of my head position &
alphaare animatable, but I’m uncertain of Color. (Alpha is just afloatvalue, and center is just aCGPoint, both of which are primitives, butUIColoris a referenced type and UIView may not know how to animate a pointer.)