How to change blur depth in swift? I found a code with which i blurred my UIView, but it blurs to hard, how i can decrease blur depth (radius)? Here is code example
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let blurEffect = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.translatesAutoresizingMaskIntoConstraints = false
view.insertSubview(blurView, at: 0)
NSLayoutConstraint.activate([
blurView.topAnchor.constraint(equalTo: view.topAnchor),
blurView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
blurView.heightAnchor.constraint(equalTo: view.heightAnchor),
blurView.widthAnchor.constraint(equalTo: view.widthAnchor)
])
}
CodePudding user response:
you can do it using this animation trick
var animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
var effect = UIBlurEffect?
private func blurIt() {
animator.stopAnimation(true)
effect = nil
animator.addAnimations { [weak self] in
self?.effect = UIBlurEffect(style: .light)
}
animator.fractionComplete = 0.1 //This is your blur intensity in range 0 - 1
}
or you can try changing the alpha of the blurView
blurView.alpha = 0.1
Obviously the final result is not the same