我想在一个UIButton上有一些脉冲动画(无限循环"放大-缩小"),这样它就能立即引起用户的注意.
我看到了这个链接How to create a pulse effect using -webkit-animation - outward rings,但我想知道是否有办法只使用本机框架来实现这一点?
我想在一个UIButton上有一些脉冲动画(无限循环"放大-缩小"),这样它就能立即引起用户的注意.
我看到了这个链接How to create a pulse effect using -webkit-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
Swift个
let pulseAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.opacity))
pulseAnimation.duration = 1
pulseAnimation.fromValue = 0
pulseAnimation.toValue = 1
pulseAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
pulseAnimation.autoreverses = true
pulseAnimation.repeatCount = .greatestFiniteMagnitude
view.layer.add(pulseAnimation, forKey: "animateOpacity")