ios - 动画 block 动画中的 UITableViewCell 背景颜色

标签 ios animation uitableview block uibackgroundcolor

我正在尝试将两个表格单元格的背景颜色从红色变为原始颜色白色。

以下代码是我正在使用的。问题是它从不显示红色——它只是从(原始)白色动画到(动画到)白色。即,如果我更改动画 block 中的颜色,它将动画为该颜色。

[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) {

}];

那么,为什么当我的表格背景有动画时,我的单元格背景没有动画呢?

值得一提的是,在此之后,我在 table view 上执行了许多其他链接动画,但是在将这些动画注释掉之后,我仍然有这个问题。

最佳答案

因为一个单元格包含其他 View 。您必须检查 cell.contentView 的颜色, cell.accessoryViewcell.backgroundView .如果所有这些都是[UIColor clearColor] , 你可以只动画 cell.backgroundColor .

关于ios - 动画 block 动画中的 UITableViewCell 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10984002/

相关文章:

ios - 从 UITableView 创建 pdf 文件

IE 8 中的 JQuery Accordion 错误?解决方法?

ios - 如果单击 UISearchBar,则更改 UITableView 位置 : [using ModernSearchBar]

ios - 自定义 UITableViewCell 在 iPad 上宽度错误

iphone - 带按钮的自定义 UINavigationController

ios - 如何为 iOS 扩展定义 pod 文件

android - 尝试稍等片刻,然后刷新适配器

ios - UINavigationBar 大标题重影

iphone - UITableViewCell 标签 opaque=YES 单击单元格时看起来很糟糕

ios - 自定义 UITableViewCell 高度在移动时发生变化