迅捷脉冲动画 [英] Swift Pulse Animation
问题描述
我正在尝试制作脉冲动画,我发现了这一点:
ios-如何执行本地";脉冲效应" UIButton上的动画
这很有用,但我还需要其他东西,
所以我有文本框,UITextField
有边框,
当您专注于它时,我希望边框改变颜色,但是以特定的方式
我希望它从中心开始然后传播,我找不到动画,所以我将尝试通过文本进行演示:B =黑色
Y =黄色.
这是边界:
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
边界集中起来:
BBBYBBB
BBYYYBB
BYYYYYB
YYYYYYY
动画结束了, 聚焦失败:
animation is over, focuse lost:
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)
它可以工作,但我需要它做其他事情
it works but i need it to do something else
推荐答案
在这里
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)
这篇关于迅捷脉冲动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!