iphone – ios – 如何做一个本地的“脉冲效果”动画在UIButton

我想在UIButton上有某种脉冲动画(无限循环“scale in-scale out”),以便立即获得用户的注意。

我看到这个链接How to create a pulse effect using -web-kit animation – outward rings,但我想知道是否有任何方式做这只使用本机框架?

任何帮助非常感谢 – 代码示例甚至更好;-)

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

迅速

let pulseAnimation = CABasicAnimation(keyPath: "opacity")
pulseAnimation.duration = 1
pulseAnimation.fromValue = 0
pulseAnimation.toValue = 1
pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount = FLT_MAX
self.view.layer.addAnimation(pulseAnimation, forKey: "animateOpacity")

See this article

http://stackoverflow.com/questions/8083138/ios-how-to-do-a-native-pulse-effect-animation-on-a-uibutton

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:iphone – ios – 如何做一个本地的“脉冲效果”动画在UIButton