1

In my iOS app I am using UITableView with max. 8 rows (number of rows can change but maximum is 8). I am downloading some data which are processed and presented in the table view.

If some data are not correct (out of range or anything) I need to inform the user about that. This warning should be row flashing. If some value on position 2 is not correct, row 2 should be flashing (white/red).

I need advice what is the best way how to implement that.

Only idea I have is to implement backgroud timer which runs in 500ms interval and everytime checks the array with data and if some data are not correct, it changes background color of the particular row (if the backgroud color is white, it is changed to red and oposite). This should look like flashing.

Is that OK or do you have better idea? Thanks

4

1 回答 1

0

界面视图

您可以使用动画方法UIView处理事物的动画方面......

这个问题有几个答案,你应该如何重复动画,在每个循环之间检查动画是否应该继续或停止。

但是,鉴于您想开始一个连续的动画并根据其他事件中断/停止它,我认为使用 aCABasicAnimation可能会更好......

CABasic动画

您可以使用CABasicAnimationbackgroundColor.UITableViewCell

例如,下面是一些我用来为 a 的颜色设置动画的代码UIView

// UIView* _addressTypeTokenView;
// UIColor* _tokenOnColour;
// UIColor* _tokenOffColour;

CABasicAnimation* colourChange = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
colourChange.fromValue = (__bridge id)(_tokenOffColour.CGColor);
colourChange.toValue = (__bridge id)(_tokenOnColour.CGColor);
colourChange.duration = 0.6;
colourChange.delegate = self;
_addressTypeTokenView.layer.backgroundColor = _tokenOnColour.CGColor;
[_addressTypeTokenView.layer addAnimation:colourChange forKey:@"colourChangeAnimation"];

您将要创建一个永远重复的动画。(根据有关此主题的相关问题HUGE_VALF)使用创建这样的动画是合法的。例如

colourChange.repeatDuration = HUGE_VALF;

一旦你创建了CABasicAnimation你将它添加到有CALayer问题的视图中,连同一个键:

- (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key

在上面的示例中,我使用了密钥@"colourChangeAnimation"

[_addressTypeTokenView.layer addAnimation:colourChange forKey:@"colourChangeAnimation"];

稍后可以使用该键删除动画,使用以下方法:

- (void)removeAnimationForKey:(NSString *)key

您仍然需要定期检查数据是否仍然有效。如果它变为有效,您可以删除动画以停止闪烁效果。

您可以使用计时器检查视图控制器,或者让模型对象处理数据有效性检查并使用委托回调与视图控制器进行通信(分离职责并保持视图控制器整洁)。

无论您如何处理数据有效性检查,该CABasicAnimation方法都提供了一种启动和停止动画的简洁方式。

于 2015-08-11T10:00:58.203 回答