我正在尝试制作一个脉冲动画,我发现:How to do a native "Pulse effect" animation on a UIButton - iOS很有用,但我需要其他东西,所以我有textfield,UITextField,它有边框,当你关注它时,我希望边框改变颜色,但以特定的方式
我希望它从中心开始,然后扩散,我找不到动画,所以我将尝试通过文本演示它:B = Black,Y = Yellow。
这是边界:
BBBBBBB边框获得焦点:
BBBYBBB
BBYYYBB
BYYYYYB
YYYYYYY动画结束,焦点丢失:
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)它可以工作,但我需要它来做其他事情
发布于 2016-04-11 00:22:42
此动画在3秒内连续从0到1不透明度脉冲:
let pulseAnimation = CABasicAnimation(keyPath: "opacity")
pulseAnimation.duration = 3
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
复制相似问题