我正在尝试使用+[UIView animateWithDuration:animations:]
方法将UITableViewCell
的背景颜色从白色动画化为红色。但是,颜色不会动画化,它会立即跳到红色。我已经将setBackgroundColor:
切换为setOpacity:
,效果很好。是什么原因导致动画无法使用背景色?以下是我正在使用的代码:
UITableView * tableView = (UITableView *)[self view];
[UIView animateWithDuration:0.2 animations:^{
[[tableView cellForRowAtIndexPath:
[NSIndexPath indexPathForRow:0 inSection:0]]
setBackgroundColor:[UIColor redColor]];
}];
不能对颜色属性的更改设置动画。您必须创建两个背景视图,并使用它们的.alpha
属性在它们之间淡入淡出。