swift 5的模糊深度



如何在swift中改变模糊深度?我发现了一个代码,我模糊了我的UIView,但它模糊到很难,我怎么能减少模糊深度(半径)?下面是代码示例

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)
])
}

你可以使用这个动画技巧

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
}

或者你可以尝试改变blurView

的alpha值
blurView.alpha = 0.1

显然最后的结果是不一样的

相关内容

  • 没有找到相关文章

最新更新