0

我在 UITextField 上创建了一个类别,它允许在红色和白色之间进行动画处理,如下所示:

@implementation UITextField (Additions)

-(void) flash
{
    [UIView animateWithDuration:2.0 animations:^{

        [self setBackgroundColor:[UIColor redColor]];

    } completion:^(BOOL finished) {

        [self setBackgroundColor:[UIColor whiteColor]];
    }];

}

@end

我这样称呼它:

[self.paymentTextField flash];

第一次工作,它显示红色背景,然后切换回白色。但是在第二次调用时它什么也没做。

4

1 回答 1

1

我不确定为什么这不起作用。我试过了,得到了同样的东西。但是,由于颜色并没有真正的动画,你可以这样做:

self.backgroundColor = [UIColor redColor];
[self performSelector:@selector(setBackgroundColor:) withObject:[UIColor whiteColor] afterDelay:2];

这应该给你同样的外观。

于 2013-07-11T16:47:16.697 回答