0

I am adding a UIVisualEffectView for a blur over on my view. the backgound of my view is a ca gradient layer and when I add the blur, it just goes gray.

enter image description here

Greyed out blurred

This is the fade view:

    let fadeView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffect.Style.light))

This code is run when button is pressed:

    fadeView.frame = view.frame
    fadeView.center = view.center
    fadeView.alpha = 0.0
    fadeView.layer.zPosition = 1
    fadeView.isOpaque = true
    view.addSubview(fadeView)
    UIView.animate(withDuration: 0.3, animations: {self.fadeView.alpha = 1.0})

Any Help Making it blur over all the colours of the view instead of just this weird grey?

2 Answers2

1

I have tried your same code in Xcode 10.1

Output:

enter image description here

Code:

func BlurScreen() {

    let fadeView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffect.Style.dark))
    fadeView.frame = view.frame
    fadeView.center = view.center
    fadeView.alpha = 0.0
    fadeView.layer.zPosition = 1
    fadeView.isOpaque = true
    view.addSubview(fadeView)
    UIView.animate(
        withDuration: 1.3,
        animations: {
            fadeView.alpha = 1.0
        }
    )
}
McDonal_11
  • 3,935
  • 6
  • 24
  • 55
0

Try to add your blurredView without fade transition. Indeed, the UIVisualEffectView does not work well with alpha so it could explain the problem. There is a paragraph in the documentation about that:

Setting the Correct Alpha Value

When using the UIVisualEffectView class, avoid alpha values that are less than 1. Creating views that are partially transparent causes the system to combine the view and all the associated subviews during an offscreen render pass. UIVisualEffectView objects need to be combined as part of the content they are layered on top of in order to look correct. Setting the alpha to less than 1 on the visual effect view or any of its superviews causes many effects to look incorrect or not show up at all.

Community
  • 1
  • 1
Johan Drevet
  • 225
  • 2
  • 8
  • I tried this and just had it added as a subview without the whole alpa thing but it still showed up as a grey screen. Although, I can see a bit through it but it doesn't keep my background gradient colours @JohanDrevet – Peter Dutton Jan 24 '19 at 10:00