淡入淡出动画UITableViewCell

时间:2011-03-09 16:01:01

标签: iphone animation uitableview

我有一个UITableViewController,用一些我从网上下载的数据填充UITableView。每个单元格的数据也包含一个用作背景的图像,我在一个单独的NSOperation中下载添加到NSOperationQueue中,MaxConcurrentOperationCount设置为4.只要图像没有下载我就会显示一个通用占位符,我想在下载的图像成功下载后替换(淡出/淡入)。

我在UITableViewController的cellForRowAtIndexPath内使用以下代码。

[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
cell.placeholderUIImage.alpha = 0.0;
cell.backgroundUIImage.alpha = 1.0;
[UIView commitAnimations];

遗憾的是,这只是随机工作了几行,因为最多会立即设置背景图像,就好像下一次调用beginAnimations时,一个单元格上的动画会被“覆盖”

1 个答案:

答案 0 :(得分:7)

UITableView内置支持使用淡化动画重新加载行,只需调用[tableView reloadRowsAtIndexPaths:... withRowAnimation:UITableViewRowAnimationFade]并确保您的cellForRowAtIndexPath不返回已在其中的UITableViewCell实例桌子。

相关问题