How to fade a UIVisualEffectView and/or UIBlurEffect in and out?

后端 未结 15 1040
故里飘歌
故里飘歌 2020-12-04 08:38

I want to fade a UIVisualEffectsView with a UIBlurEffect in and out:

var blurEffectView = UIVisualEffectView()
blurEffectView = UIVisualEffectView(effect: UI         


        
15条回答
  •  独厮守ぢ
    2020-12-04 09:23

    I think this is new in iOS9, but you can now set the effect of a UIVisualEffectView inside an animation block:

    let overlay = UIVisualEffectView()
    // Put it somewhere, give it a frame...
    UIView.animate(withDuration: 0.5) {
        overlay.effect = UIBlurEffect(style: .light)
    }
    

    Set it to nil to remove.

    VERY IMPORTANT - When testing this on the simulator, make sure to set your simulator's Graphics Quality Override to High Quality in order for this to work.

提交回复
热议问题