【问题标题】:How to reduce blur effect on UIVisualEffectView如何减少 UIVisualEffectView 上的模糊效果
【发布时间】:2018-08-20 16:07:22
【问题描述】:

如何减少 UIVisualEffectView 上的模糊效果,它为我提供了光、extraLight 和黑暗的选项,这对我来说还不够好,我正在尝试实现这样的目标

【问题讨论】:

标签: ios swift uivisualeffectview uiblureffect


【解决方案1】:

我们完全可以使用动画师以正确的预期外观完全原生地做到这一点

用法:

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

BlurEffectView 实现:

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

【讨论】:

    【解决方案2】:

    没有改变模糊级别的官方方法。

    但是,您可以尝试以下方法:

    Create a custom blur view

    【讨论】:

      【解决方案3】:

      我知道这已经很晚了,但是如果您只是使用模糊进行模态演示,Apple 有一个名为 blurOverFullScreen 的内置 UIModalPresentationStyle,它工作得很好。

      只需将父控制器的 modalPresentationStyle 设置为 .blurOverFullScreen 并呈现新的视图控制器。如果新视图小于屏幕,则背景应该像您的图片一样模糊。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-12
        • 1970-01-01
        • 2015-02-05
        • 1970-01-01
        • 2020-12-05
        • 2019-02-02
        • 2014-07-26
        • 1970-01-01
        相关资源
        最近更新 更多