0

How can i reduce the blur effect on a UIVisualEffectView it gives me options of light, extraLight and dark which are not good enough for me i am trying to achieve something like this enter image description here

Sagaya Abdul
  • 121
  • 1
  • 11
  • Possible duplicate of [Less Blur with \`Visual Effect View with Blur\`?](https://stackoverflow.com/questions/29498884/less-blur-with-visual-effect-view-with-blur) – Tamás Sengel Mar 12 '18 at 15:27
  • 1
    If what's explained in the dup link doesn't help, consider using CoreImage. Not only do you have more control over a blur effect, you have eight different ones. –  Mar 12 '18 at 15:35
  • check this post https://stackoverflow.com/questions/41156542/how-to-blur-an-existing-image-in-a-uiimageview-with-swift/41157042#41157042 – Joe Mar 12 '18 at 16:43

3 Answers3

3

We can do that absolutely natively and with correct expected look using animator

Usage:

let blurEffectView = BlurEffectView()
view.addSubview(blurEffectView)

BlurEffectView realisation:

class BlurEffectView: UIVisualEffectView {
    
    var animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
    
    override func didMoveToSuperview() {
        guard let superview = superview else { return }
        backgroundColor = .clear
        frame = superview.bounds //Or setup constraints instead
        setupBlur()
    }
    
    private func setupBlur() {
        animator.stopAnimation(true)
        effect = nil

        animator.addAnimations { [weak self] in
            self?.effect = UIBlurEffect(style: .dark)
        }
        animator.fractionComplete = 0.1   //This is your blur intensity in range 0 - 1
    }
    
    deinit {
        animator.stopAnimation(true)
    }
}
bodich
  • 1,172
  • 10
  • 25
0

There is no official way to change the blur level.

However, you can try something like this:

Create a custom blur view

-1

I know this is late, but if you're just using blur for a modal presentations, apple has a built-in UIModalPresentationStyle called blurOverFullScreen, and it works pretty well.

Just set the parent controller's modalPresentationStyle to .blurOverFullScreen and present the new view controller. If the new view is smaller than the screen, the background should be blurred out like seen in your picture.

Ethan Zhao
  • 219
  • 1
  • 6
  • 17