gpt4 book ai didi

ios - 如何在 UIButton 上制作原生 "Pulse effect"动画 - iOS

转载 作者:IT老高 更新时间:2023-10-28 11:21:13 25 4
gpt4 key购买 nike

我想在 UIButton 上制作某种脉冲动画(无限循环“缩小 - 缩小”),以便立即引起用户的注意。

我看到了这个链接 How to create a pulse effect using -webkit-animation - outward rings但我想知道是否有任何方法可以仅使用 native 框架来做到这一点?

最佳答案

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")

See the article "Animating Layer Content"

关于ios - 如何在 UIButton 上制作原生 "Pulse effect"动画 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8083138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com