2011-05-29 57 views
1

我试图在tableview单元格中设置文本的alpha值。当我动画所有单元格时,它运作良好。但是,当我尝试着动画时,几乎没有任何事情发生。UITableViewCell中的文本动画

我有子归类细胞,并调用了自定义单元格的方法:

[cell setCellWithObject:customObject animate:YES]; 

而且方法:

- (void) setCellWithObject:(CustomObject *) obj animate:(BOOL) anim{ 
    textlabel.text = obj.name; 
    if (anim){ 
     [UIView beginAnimations:@"fade" context:nil]; 
     [UIView setAnimationDuration:0.9]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationRepeatCount:5.0]; 
     [self.textlabel setAlpha:0.4]; 
     [self.textlabel setAlpha:1]; 
     [UIView commitAnimations]; 
    } 
} 

有什么建议?

编辑:

此代码实际工作。原来,我重新加载了两次tableview。这就是为什么动画没有显示。

我的错误。

回答

0

其实这段代码的工作原理!

我只是在愚蠢地设置细胞。

0

您想在动画代码之外放置一个'setAlpha'调用。例如

[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]; 
+0

感谢您的提示!虽然不是问题,但它在我为所有单元格设置动画时有效。 – johan 2011-05-31 05:46:56