3

目前,我正在开发 UITableViewController。在其 UITableView 的单元格中,它显示来自 Web 服务的实时数据。当基础数据项之一更新(每两分钟左右一次)时,我希望单元格短暂“闪烁”,以便用户了解该单元格的数据刚刚更新。

到目前为止,我使用了以下代码:

[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseInOut animations:^
{
    cell.contentView.backgroundColor = flashColor;
} completion:^(BOOL finished)
{
    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseInOut animations:^
    {
        cell.contentView.backgroundColor = [UIColor clearColor];
    } completion: NULL];
}];

这很好用,直到我想为用户提供一种方法来“查看”给定单元格的数据并添加披露指标。由于框架缩小了内容区域为 Disclosure Indicator 腾出空间,现在 flash 只高亮了左侧 90% 的单元格,但 Disclosure Indicator 的背景颜色没有改变。

cell.accessoryView.backgroundColor = flashColor;

cell.backgroundView.backgroundColor = flashColor;

无助于修复动画。

我读过关于- (void) setHighlighted: (BOOL)highlighted animated: (BOOL)animated,但这不会在闪存后立即恢复突出显示的状态,除非我编写了大量令人讨厌的容易出错的代码来防止它飞散。此外,我无法控制动画本身。

有没有办法保持旧的动画效果与附件视图存在,还是我必须开始使用高亮方法进行闪光?

最好的问候,克里斯

4

1 回答 1

6
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseInOut animations:^
{
    [cell setHighlighted:YES animated:YES];
} completion:^(BOOL finished)
{
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveEaseInOut animations:^
    {
        [cell setHighlighted:NO animated:YES];
    } completion: NULL];
}];

请注意,单元格将忽略animateWithDuration参数中设置的时间,并始终使用 iOS 默认值 0.2 秒。所以最好将该参数设置为 0.2。

解决方法很简单,但当然不能保留原始动画(快速高亮和慢速淡出)。另一方面,这可能是更保守和面向未来的方式。

感谢大卫 Rö​​nnqvist!

克里斯

于 2012-05-25T10:59:22.180 回答