2

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?)

Community
  • 1
  • 1
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97

1 Answers1

6

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Oh, of course. I started with the UIView animation block because I was trying to animate the background colour of the UITextField directly, but despite the docs indicating it should, that simply doesn't work. – Robert Atkins Nov 29 '11 at 13:33
  • ... but, as edited, I can't get an implicit CABasicAnimation to work either. – Robert Atkins Nov 30 '11 at 07:27
  • Works just fine for me with an explicit animation (`CABasicAnimation`). – Ole Begemann Nov 30 '11 at 13:32