2012-06-11 129 views
2

的backgroundColor我试图从红色动画双表格单元背景颜色回原来的颜色,白色。动画效果的UITableViewCell的块动画

下面的代码是我使用的是什么。问题是它从不显示红色 - 它只是从(原始)白色动画到(动画到)白色。也就是说,如果我改变动画块中的颜色,它将动画成该颜色。

[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].backgroundColor = [UIColor redColor]; 
[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]].backgroundColor = [UIColor redColor]; 

[UIView animateWithDuration:0.8 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
    [table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].backgroundColor = [UIColor whiteColor]; 
    [table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]].backgroundColor = [UIColor whiteColor]; 
} 
completion:^(BOOL finished) { 

}]; 

下面的代码将按预期为表的背景,但是这不是我想要的:

table.backgroundColor = [UIColor redColor]; 

[UIView animateWithDuration:0.8 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
    table.backgroundColor = [UIColor clearColor]; 
} 
completion:^(BOOL finished) { 

}]; 

那么,为什么当我的表背景不我的手机背景动画?

对于它的价值,我有一堆其他链接的动画我在这之后对上表视图进行的,不过话说评论这些动画的时候,我还是有这个问题。

+0

TableView单元对于它们的背景颜色有点神奇。你只能在tableView:willDisplayCell:forRowAtIndexPath方法中设置单元格的背景颜色(通过'UIView'中的'backgroundColor'属性),而不是其他任何地方。请参阅文档以获取更多信息https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006938 –

回答

0

看起来@Jason可可是正确的。我不能这样做(清洁,快速):

从苹果:

注意:如果你想通过设置 一个单元格的背景颜色更改单元格(背景颜色由UIView声明的backgroundColor属性 )必须在 tableView:willDisplayCell:forRowAtIndexPath:代理 的方法中执行,而不是在数据源的tableView:cellForRowAtIndexPath中执行。 更改细胞的一组式表视图 背景颜色具有在IOS 3.0的效果比的 操作系统先前版本不同。它现在影响圆角 矩形内的区域,而不是其外部的区域。 Reference

所以,如果我真的想我不得不设置一些变量,然后调用在桌子上或类似的东西reloadData

0

由于单元格中包含的其他意见。你必须检查颜色cell.contentView,cell.accessoryViewcell.backgroundView。如果所有这些都是[UIColor clearColor],则只需制作cell.backgroundColor即可。

+0

这没有奏效为了我。 –