简体   繁体   中英

How do I animate changing the border colour of a UITextField?

I infer from this question that the following should animate the colour change of my UITextField's border:

        [UIView animateWithDuration:5.0f animations:^() {
            myUITextField.layer.borderColor = [UIColor greenColor].CGColor;
        }];

But it doesn't, the border changes colour instantly. Is it obvious what I'm doing wrong?

Update: Ok, so trying the following implicit animation :

        [CATransaction begin];
        [CATransaction setValue:[NSNumber numberWithFloat:5.0f] forKey:kCATransactionAnimationDuration];
            myUITextField.layer.borderColor = [UIColor greenColor].CGColor;
        [CATransaction commit];

And that doesn't animate either, same effect: it changes colour instantly (as an aside, where's the default for kCATransactionAnimationDuration for layer.borderColor documented?)

I believe that CALayer properties are not animatable in a UIView animation block. You would need to set up a CABasicAnimation and add that animation to the layer instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM