[英]How do I animate changing the border colour of a UITextField?
我從這個問題推斷出以下內容應該可以動畫化UITextField邊框的顏色變化:
[UIView animateWithDuration:5.0f animations:^() {
myUITextField.layer.borderColor = [UIColor greenColor].CGColor;
}];
但事實並非如此,邊框會立即更改顏色。 我在做什么錯很明顯嗎?
更新:好的,所以嘗試以下隱式動畫 :
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:5.0f] forKey:kCATransactionAnimationDuration];
myUITextField.layer.borderColor = [UIColor greenColor].CGColor;
[CATransaction commit];
而且這也不會產生動畫效果,具有相同的效果:它會立即改變顏色(順便說一句,layer.borderColor的kCATransactionAnimationDuration的默認值在哪里?)
我相信CALayer
屬性在UIView
動畫塊中無法設置動畫。 您將需要設置CABasicAnimation
並將該動畫添加到圖層中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.