淡入/淡出UILabel

时间:2018-07-27 09:51:49

标签: ios swift uilabel uiviewanimation

我的stackview包含2个标签。我想给隐藏过程设置动画,例如当其中一个标签被隐藏时给它淡入淡出动画,或者当其中一个标签被隐藏时给它淡入淡出动画。我该怎么办?

2 个答案:

答案 0 :(得分:1)

您应为alpha中的label设置动画。

UIView.animate(withDuration: 1, animations: {
    disclaimerLabel.alpha = 0
}

答案 1 :(得分:0)

    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)