淡出 in/out 一个 UILabel
Fading in/out a UILabel
我的堆栈视图包含 2 个标签。我想为隐藏过程设置动画,例如当其中一个标签被隐藏时给它一个淡出动画,或者当其中一个标签未隐藏时给它一个淡入淡出动画。我该怎么做?
let flash = CABasicAnimation(keyPath: "opacity")
flash.duration = 0.5
flash.fromValue = 1
flash.toValue = 0.1
flash.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
flash.autoreverses = true
flash.repeatCount = 3
la1.layer.add(flash, forKey: nil)
您应该为 label
的 alpha
添加动画。
UIView.animate(withDuration: 1, animations: {
disclaimerLabel.alpha = 0
}
我的堆栈视图包含 2 个标签。我想为隐藏过程设置动画,例如当其中一个标签被隐藏时给它一个淡出动画,或者当其中一个标签未隐藏时给它一个淡入淡出动画。我该怎么做?
let flash = CABasicAnimation(keyPath: "opacity")
flash.duration = 0.5
flash.fromValue = 1
flash.toValue = 0.1
flash.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
flash.autoreverses = true
flash.repeatCount = 3
la1.layer.add(flash, forKey: nil)
您应该为 label
的 alpha
添加动画。
UIView.animate(withDuration: 1, animations: {
disclaimerLabel.alpha = 0
}