Chr*_*ris 3 core-animation uitableview ios
目前,我正在开发一个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];
}];
Run Code Online (Sandbox Code Playgroud)
这很有效,直到我想为用户提供一种"查看"给定单元格数据并添加Disclosure Indicators的方法.由于框架缩小了内容区域以便为Disclosure Indicator腾出空间,现在flash只突出显示单元格的左侧90%,但Disclosure Indicator的背景颜色不会改变.
cell.accessoryView.backgroundColor = flashColor;
Run Code Online (Sandbox Code Playgroud)
和
cell.backgroundView.backgroundColor = flashColor;
Run Code Online (Sandbox Code Playgroud)
无助于修复动画.
我已经读过了- (void) setHighlighted: (BOOL)highlighted animated: (BOOL)animated,但是在闪存之后不会立即恢复突出显示的状态,除非我写了大量令人讨厌的容易出错的代码,以防止它分崩离析.此外,我无法控制动画本身.
有没有办法保持旧的动画效果与附件视图存在,或者我是否必须使用突出显示方法开始使用闪光灯?
最诚挚的问候,克里斯
[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];
}];
Run Code Online (Sandbox Code Playgroud)
请注意,单元格将忽略animateWithDuration参数中设置的时间,并始终使用默认值为0.2秒的iOS.因此,将该参数设置为0.2是个好主意.
解决方案很简单,但当然无法保留原始动画(快速突出显示和慢速淡出).另一方面,这可能是更加保守和面向未来的方式.
感谢DavidRönnqvist!
克里斯
| 归档时间: |
|
| 查看次数: |
3538 次 |
| 最近记录: |