Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit the UIBlurEffect intensity?

Tags:

I don't want my background image to be too blury. Isn't there a property to adjust the blur intensity?

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light) blurEffect.??? let effectView = UIVisualEffectView(effect: blurEffect) effectView.frame = backgroundAlbumCover.bounds backgroundAlbumCover.addSubview(effectView) 
like image 227
Christos Weip Avatar asked Jan 25 '15 19:01

Christos Weip


1 Answers

You can do that in super elegant way with animator

(reducing UIVisualEffectView alpha will not affect blur intensity, so we must use animator)

Usage as simple as:

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)     } } 
like image 153
bodich Avatar answered Sep 30 '22 21:09

bodich