UIView动画过早终止

时间:2011-07-05 10:32:22

标签: cocoa-touch uikit core-animation

我正在尝试使用+[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]];
}];

1 个答案:

答案 0 :(得分:0)

您无法为颜色属性设置更改动画。您必须使用.alpha属性创建两个背景视图并在它们之间淡入淡出。

相关问题