问题
i'm trying to make a pulse animation, i've found this:
ios - how to do a native "Pulse effect" animation on a UIButton
and it was useful, but i need something else,
so i have textfield, UITextField
which has border,
when you focus on it i want the border to change color, but in specific way
i want it to start from center and then spread, i could not find the animation so i will try to demonstrate it by text:B = Black
Y = Yellow.
this is border:
BBBBBBB
border gets focused:
BBBYBBB
BBYYYBB
BYYYYYB
YYYYYYY
animation is over, focuse lost:
BYYYYYB
BBYYYBB
BBBYBBB
BBBBBBB
my code looks something like this:
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)
it works but i need it to do something else
回答1:
Here you go
let pulseAnimation = CABasicAnimation(keyPath: "opacity")
pulseAnimation.duration = 30
pulseAnimation.fromValue = 0
pulseAnimation.toValue = 1
pulseAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount =.greatestFiniteMagnitude
self.view.layer.add(pulseAnimation, forKey: nil)
来源:https://stackoverflow.com/questions/34761022/swift-pulse-animation