模糊背景在iOS14中不再起作用

时间:2020-10-01 16:01:01

标签: ios swift xcode ios14

当前正在为他人处理别人的现有项目,但是在iOS14设备上出现这个怪异的问题,仅是因为每个背景模糊的屏幕都不再显得模糊了,而是像透明的灰色叠加图像(具有较低的alpha值)一样。香港专业教育学院尝试了各种事情,并上网寻找,但仍然无法在这里找到问题。

  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    animatedCircleView.alpha = 1

    imvLogo.isHidden = false
    
    // Hero
    imvLogo.hero.id = "logo"
    imvLogo.hero.modifiers = [.duration(self.animatedDuration)]
    
    let blurEffect = (NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type).init()
    blurEffect.setValue(8, forKeyPath: "blurRadius")
    blurView = UIVisualEffectView(effect: blurEffect)
    blurView.frame = UIScreen.main.bounds
    blurView.alpha = 1
    view.insertSubview(blurView, aboveSubview: imvBackground)
  }

以下是iOS13上背景模糊的样子:

enter image description here

enter image description here

这是现在在iOS14上的样子:

enter image description here

enter image description here

我也尝试将代码更改为此,但是它只是为我提供了纯正的背景色,而不是模糊的背景:

let blurEffect = UIBlurEffect(style: .light)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = UIScreen.main.bounds
blurEffectView.alpha = 0
view.insertSubview(blurEffectView, aboveSubview: viewUnder)

以下是纯色背景颜色,代替了我

enter image description here

如果有人可以告诉我什么可能是错误的,或者是什么在iOS14中破坏了它,那将是很好的,我将如何解决这个问题。谢谢。

更新:

我检查了视图层次结构,并在ios13上正确创建了UIVisualEffectBackdropView(见图):

enter image description here

但是ios14 UIVisualEffectBackdropView的创建不正确,只是获取背景图像并对其应用了色调,但没有模糊:

enter image description here

1 个答案:

答案 0 :(得分:1)

@GameDev

实际上,此代码使用自iOS 14起不再可用的私有API _UICustomBlurEffect。 您必须依靠常规的UIBlurEffect子类,但无法设置blurRadius ...