gpt4 book ai didi

ios - 使用 accessoryView 为 UITableViewCell 的 backgroundColor 设置动画

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:12:02 26 4
gpt4 key购买 nike

目前,我正在研究 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];
}];

这很有效,直到我想为用户提供一种方法来“查看”给定单元格的数据并添加披露指标。由于内容区域被框架缩小以便为披露指示器腾出空间,现在闪光灯仅突出显示单元格的左侧 90%,但披露指示器的背景颜色没有改变。

cell.accessoryView.backgroundColor = flashColor;

cell.backgroundView.backgroundColor = flashColor;

不会帮助修复动画。

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

有没有一种方法可以让旧的动画效果与附件 View 一起出现,或者我是否必须使用高亮方法开始制作闪光灯?

最好的问候,克里斯

最佳答案

[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 是个好主意。

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

感谢 David Rönnqvist!

克里斯

关于ios - 使用 accessoryView 为 UITableViewCell 的 backgroundColor 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10735144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com