Fade In Fade Out Animation

后端 未结 13 1169
生来不讨喜
生来不讨喜 2021-01-30 01:45

Here is some code I struggle with for a while.

If you start the fade in animation, the label text fades in. If I start the fade out animation the the label text fades ou

13条回答
  •  佛祖请我去吃肉
    2021-01-30 02:00

    Swift 5 version of iPhoneDeveloper's answer:

    extension UIView {
        
        func fadeIn() {
            UIView.animate(withDuration: 1.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
                self.alpha = 1.0
            }, completion: nil)
        }
        
        func fadeOut() {
            UIView.animate(withDuration: 1.0, delay: 0.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
                self.alpha = 0.0
            }, completion: nil)
        }
    }
    

提交回复
热议问题