如何动画更改UITextField的边框颜色? [英] How do I animate changing the border colour of a UITextField?
问题描述
我从这个以下问题应该为我的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];
这也没有动画,效果相同:它立即改变颜色(顺便说一下,哪里有对于layer.borderColor记录的kCATransactionAnimationDuration的默认值是什么?)
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?)
推荐答案
我相信 CALayer
c> UIView 动画块中的$ c>属性不可动画。您需要设置 CABasicAnimation
并将该动画添加到图层中。
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.
这篇关于如何动画更改UITextField的边框颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!