views:

586

answers:

1

I have a UIView as a subview of a custom subclass of UITableViewCell. I'm using it to change the color of just a small area of the cell dynamically.

When I select the cell, the background color of the entire cell -- including the background color of the subview -- is changed to blue. That's fine, it happens instantaneously. Selection drills down to another view controller.

However, when I come back from the view controller, it animates the background again from blue to white -- but it doesn't animate the background color of my subview. The effect is blue animated to white, then abruptly changing back to my original color.

How do I either

  • exempt this subview's background color from changing at all,
  • or animate the transition so that my color gets returned nicely?

Thanks!

A: 

The following shows how to animate a colour change:

UIView * blue = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 20)];
[self.view addSubview:blue];
blue.backgroundColor = [UIColor whiteColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
blue.backgroundColor = [UIColor blueColor];
[UIView commitAnimations];
[blue release];

Hopefully, you can adapt it to suit your needs.

Tom

Tom Irving