【问题标题】:UIView animationWithDuration not working second when called twiceUIView animationWithDuration 在调用两次时不起作用
【发布时间】:2013-07-11 16:24:25
【问题描述】:

我在 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];

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

【问题讨论】:

标签: ios cocoa-touch uitextfield


【解决方案1】:

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

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

这应该给你同样的外观。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    • 2012-05-28
    • 1970-01-01
    • 2018-06-15
    • 2016-03-30
    相关资源
    最近更新 更多