Animation of text in UITableViewCell
I'm trying to animate the alpha value of the text in a tableview cell. It works well when I animate all cells. But when I try to just animate a few nothing happens.
I have sub classed the cells and call a custom cell method with:
[cell setCellWithObject:customObject animate:YES];
And the method:
- (void) setCellWithObject:(CustomObject *) obj animate:(BOOL) anim{
textlabel.text = obj.name;
if (anim){
[UIView beginAnimations:@"开发者_如何学Gofade" context:nil];
[UIView setAnimationDuration:0.9];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:5.0];
[self.textlabel setAlpha:0.4];
[self.textlabel setAlpha:1];
[UIView commitAnimations];
}
}
Any advice?
EDIT:
This code actually works. Turns out that i reloaded the tableview twice. Thats why the animation didn't show.
My misstake.
You want to put one of your 'setAlpha' calls outside the animation code. e.g.
[self.textlabel setAlpha:1];
[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:0.9];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:5.0];
[self.textlabel setAlpha:0.4];
[UIView commitAnimations];
Actually this code works!
I was just beeing stupid setting up the cells.
精彩评论