gpt4 book ai didi

ios - 如何在没有警告的情况下正确地在 iOS 11 状态栏上添加模糊效果?

转载 作者:行者123 更新时间:2023-11-28 15:09:09 25 4
gpt4 key购买 nike

我曾经使用以下代码在状态栏上添加模糊效果:

// Add blur effect on status bar
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(blurEffectView)
blurEffectView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
blurEffectView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
blurEffectView.topAnchor.constraint(equalTo: self.topLayoutGuide.topAnchor).isActive = true
blurEffectView.bottomAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor).isActive = true

它从 Xcode 6 或 7 开始工作,甚至对于 Xcode 9。但是,最后两行从 Xcode 9 开始发出警告:

'topLayoutGuide' was deprecated in iOS 11.0: Use view.safeAreaLayoutGuide.topAnchor instead of topLayoutGuide.bottomAnchor

按照警告,如果我将 topLayoutGuide 更改为建议值,结果不正确(所有屏幕都是空白)。

如何在 iOS 11 中正确添加状态栏模糊效果而不出现警告?

最佳答案

blurEffectView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
blurEffectView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
blurEffectView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
blurEffectView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true

关于ios - 如何在没有警告的情况下正确地在 iOS 11 状态栏上添加模糊效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47949961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com