[英]Slide animate background color left to right UIView or UIButton
How to slide animate background color left to right UIView or UIButton Swift (iOS)如何从左向右滑动动画背景颜色 UIView 或 UIButton Swift (iOS)
Example of animating:动画示例:
div { font: 22px Arial; display: inline-block; padding: 1em 2em; text-align: center; color: white; background: red; /* default color */ /* "to left" / "to right" - affects initial color */ background: linear-gradient(to left, salmon 50%, lightblue 50%) right; background-size: 200%; transition: .5s ease-out; } div:hover { background-position: left; }
<div>Example</div>
class AnimatingButton: UIView {
func startProgressAnimation()
{
let layer = CALayer()
layer.backgroundColor = #colorLiteral(red: 0.4980392157, green: 0.8352941176, blue: 0.1921568627, alpha: 1)
layer.masksToBounds = true
layer.anchorPoint = .zero
layer.frame = CGRect.init(x: 0,
y: 0,
width: self.frame.width,
height: self.frame.height)
self.layer.addSublayer(layer)
let boundsAnim:CABasicAnimation = CABasicAnimation(keyPath: "bounds.size.width")
boundsAnim.fromValue = 0
boundsAnim.toValue = self.frame.size.width
let anim = CAAnimationGroup()
anim.animations = [boundsAnim]
anim.isRemovedOnCompletion = false
anim.duration = 10
layer.add(anim, forKey: "bounds.size.width")
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.