[英]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: 我从这个问题推断出以下内容应该可以动画化UITextField边框的颜色变化:
[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?) 而且这也不会产生动画效果,具有相同的效果:它会立即改变颜色(顺便说一句,layer.borderColor的kCATransactionAnimationDuration的默认值在哪里?)
I believe that CALayer
properties are not animatable in a UIView
animation block. 我相信
CALayer
属性在UIView
动画块中无法设置动画。 You would need to set up a CABasicAnimation
and add that animation to the layer instead. 您将需要设置
CABasicAnimation
并将该动画添加到图层中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.