xcode 迅捷脉冲动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34761022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift Pulse Animation
提问by nikagar4
i'm trying to make a pulse animation, i've found this:
ios - how to do a native "Pulse effect" animation on a UIButtonand 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:
我正在尝试制作一个脉冲动画,我发现了这个:
ios - 如何在 UIButton 上做一个原生的“脉冲效果”动画,它很有用,但我需要别的东西,所以我有文本UITextField
框,它有边框,当你专注于它时,我希望边框改变颜色,但在特定方式中我希望它从中心开始然后展开,我找不到动画所以我会尝试通过文本来演示它:B = Black Y =黄色。这是边界:
BBBBBBB
BBBBBB
border gets focused:
边框变得聚焦:
BBBYBBB
BBBYBBB
BBYYYBB
BBYYYBB
BYYYYYB
BYYYYYB
YYYYYYY
YYYYYY
animation is over, focuse lost:
动画结束,焦点丢失:
BYYYYYB
BYYYYYB
BBYYYBB
BBYYYBB
BBBYBBB
BBBYBBB
BBBBBBB
BBBBBB
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
它有效,但我需要它做其他事情
回答by BilalReffas
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)