1

I know that UIVisualEffectView ist very uncustomizable, so I can't setup the radius of blurness of the view or even the color.

Now I realized I could not even mask one.

I want to realize a Tabbar with blured Background, but to the top corner it gets sharper till 100%. Because I know I couldn't adjust the blur radius I had the idea to work with a gradient mask to archieve something like this:

Created with a graphictool

But as sad at the beginning I could not even mask a simple Rectangle:

let gradientMask = CAGradientLayer()
    gradientMask.frame = effectView.frame

    gradientMask.colors = [UIColor.black.cgColor, UIColor.clear.cgColor]

    effectView.layer.mask = gradientMask

The result is, the UIVisualEffectView doesn't show at all anymore. Have you guy a workaround or something else?

EDIT: The view in the screenshot is for example, in the final app the background is a dynamic list with tiles where I can scroll through. So the workaround with snapshots will not work in my case.

kuemme01
  • 472
  • 5
  • 19
  • I imagine this could be possible by making a runtime snapshot of the background `UIView` with the `UIVisualEffectView` effect and using the resulting snapshot image for display inside an overlaying `UIImageView` and applying the mask to that `UIImageView` while hiding the `UIVisualEffectView`. Not pretty but could work. EDIT: Other than that, [this](https://stackoverflow.com/questions/39595047/uivisualeffectview-with-mask-layer) might be related. – Eternal Black Jun 11 '19 at 10:22
  • 1
    Good idea, but doesn’t work in my case. I forgot to say, my background will be dynamic. In the final view I will have a list where I can scroll through. – kuemme01 Jun 11 '19 at 10:31
  • try to use gradient layer, instead of shape layer. see https://stackoverflow.com/questions/10814922/how-to-apply-cagradientlayer-as-mask-of-another-calayer – Kirow Jun 11 '19 at 10:49
  • or try this repo - https://github.com/KyoheiG3/DynamicBlurView – Kirow Jun 11 '19 at 10:57
  • @Kirow tried both, both with the same result. The blured view doesn't show up anymore. Tried it with blurView.mask = ... and blurView.layer.mask = ... For the mask I used a simple Rect layer, a CAGradientLayer and a UIView. – kuemme01 Jun 11 '19 at 11:10
  • I guess to create this blur effect you need to work with masks and/or alpha channels internally. Because if you adjust one of that values the effect always disappears at all – kuemme01 Jun 11 '19 at 11:13
  • @kuemme01 have you found a solution? – aheze Sep 29 '20 at 15:35
  • No sorry, I come to the end its not possible because of how UIVisualEffectView works. – kuemme01 Sep 29 '20 at 15:40

0 Answers0