HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 从WhiteColor到RedColor的UIButton的背景颜色动画大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试制作一种颜色脉冲效果来动画UIButton的背景颜色,使其从颜色(WhiteColor)连续变化到另一种颜色(RedColor).
我正在尝试使用CABasicAnimation来改变Opacity,但我也无法使用颜色.

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];
    [BigButton.layer addAnimation:theAnimation forKey:@"animateOpacity"];

我们将不胜感激.
谢谢

解决方法

我找到了正确的方法.你需要记住CGColor.这是我的错.编译器在这里没有帮助.

目标C.

CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"BACkgroundColor"];
theAnimation.duration=1.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=YES;
theAnimation.fromValue= [[UIColor redColor] CGColor];
theAnimation.toValue= [[UIColor blueColor] CGColor];
[BigButton.layer addAnimation:theAnimation forKey:@"ColorPulse"];

迅速

let colorAnimation = CABasicAnimation(keyPath: "BACkgroundColor")
colorAnimation.fromValue = UIColor.redColor().CGColor
colorAnimation.toValue = UIColor.blueColor().CGColor
colorAnimation.duration = 1
colorAnimation.autoreverses = true
colorAnimation.repeatCount = FLT_MAX
self.layer.addAnimation(colorAnimation,forKey: "ColorPulse")
@H_696_30@

大佬总结

以上是大佬教程为你收集整理的ios – 从WhiteColor到RedColor的UIButton的背景颜色动画全部内容,希望文章能够帮你解决ios – 从WhiteColor到RedColor的UIButton的背景颜色动画所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。