2016-01-13 151 views
1

我試圖做一個脈衝的動畫中,我發現這一點: ios - how to do a native "Pulse effect" animation on a UIButton ,它是有用的,但我需要別的東西, 所以我有文本框,UITextField具有邊框, 當你注意它我想邊框改變顏色,但以特定的方式 我希望它從中心開始,然後傳播,我找不到動畫,所以我會嘗試通過文本演示它:B =黑色 Y =黃色。 這是邊界:斯威夫特脈衝動畫

BBBBBBB

界限變得專注:

BBBYBBB

BBYYYBB

BYYYYYB

YYYYYYY

動畫結束後, focuse丟失:

BYYYYYB

BBYYYBB

BBBYBBB

BBBBBBB

我的代碼看起來是這樣的:

let pulseAnimation = CABasicAnimation(keyPath: "borderColor") 
    pulseAnimation.duration = 3 
    pulseAnimation.fromValue = UIColor.darkGrayColor().CGColor 
    pulseAnimation.toValue = UIColor.yellowColor().CGColor 
    pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEasInEaseOut) 
    pulseAnimation.autoreverses = true 
    //pulseAnimation.repeatCount = FLT_MAX 
    x.layer.sublayers![0].addAnimation(pulseAnimation, forKey: nil) 

它的工作原理,但我需要它做的事別的東西

回答

4

這裏你去

let pulseAnimation = CABasicAnimation(keyPath: "opacity") 
pulseAnimation.duration = 30 
pulseAnimation.fromValue = 0 
pulseAnimation.toValue = 1 
pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 
pulseAnimation.autoreverses = true 
pulseAnimation.repeatCount = FLT_MAX 
self.view.layer.addAnimation(pulseAnimation, forKey: nil)