ios - 如何做一个原生的“脉冲效应” UIButton上的动画 [英] ios - how to do a native "Pulse effect" animation on a UIButton
本文介绍了ios - 如何做一个原生的“脉冲效应” UIButton上的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在UIButton上有一些脉冲动画(无限循环缩小比例尺),以便立即引起用户注意。
I would like to have some kind of pulse animation (infinite loop "scale in - scale out") on a UIButton so it gets users' attention immediately.
我看到了这个链接如何创建一个脉冲效果使用-webkit-animation - 外向环但我想知道是否有任何方法只使用本机框架?
I saw this link How to create a pulse effect using -webkit-animation - outward rings but I was wondering if there was any way to do this only using native framework?
任何帮助非常感谢 - 代码示例甚至更好; - )
Any help much appreciated - code sample even better ;-)
推荐答案
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[theLayer addAnimation:theAnimation forKey:@"animateOpacity"]; //myButton.layer instead of
Swift
let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))
pulseAnimation.duration = 1
pulseAnimation.fromValue = 0
pulseAnimation.toValue = 1
pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount = .greatestFiniteMagnitude
self.view.layer.addAnimation(pulseAnimation, forKey: "animateOpacity")
这篇关于ios - 如何做一个原生的“脉冲效应” UIButton上的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文