gpt4 book ai didi

ios - UINavigationController - 使用 UIBlurEffect 清除背景

转载 作者:搜寻专家 更新时间:2023-11-01 07:15:37 25 4
gpt4 key购买 nike

我在 UIViewController 中使用 UIBlurEffect,它以 .crossDissolve 过渡样式呈现。 UIViewController 在其 View 中添加了一个 collectionView,因此两者都有清晰的背景。

HomeViewController.swift

func showLiveDealsCategory(sender:UITextField){
let catSelection = LiveDealCategorySelection()
//let navContr = UINavigationController(rootViewController: catSelection)
catSelection.modalPresentationStyle = .custom
catSelection.modalTransitionStyle = .crossDissolve
self.present(catSelection, animated: true, completion: nil)
}

LiveDealCategorySelection.swift

func setupBackgroundView(){
if !UIAccessibilityIsReduceTransparencyEnabled() {
self.view.backgroundColor = .clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = (self.view?.bounds)!
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view?.addSubview(blurEffectView)
} else {
self.collectionView?.backgroundColor = UIColor.black
}
}

这是您可以在 LiveDealCategorySelection 后面看到 mapView 的结果:

enter image description here

问题是当我将 View Controller 嵌入 UINavigationController 时,因为我无法将其背景颜色设置为 .clear:

func showLiveDealsCategory(sender:UITextField){
let catSelection = LiveDealCategorySelection()
let navContr = UINavigationController(rootViewController: catSelection)
catSelection.modalPresentationStyle = .custom
catSelection.modalTransitionStyle = .crossDissolve
self.present(navContr, animated: true, completion: nil)
}

LiveDealCategorySelection 我试过:

 override func viewWillAppear(_ animated: Bool) {
if self.navigationController != nil {
self.navigationController!.view.backgroundColor = .clear
self.navigationController!.view.tintColor = .clear
}
}

当我实例化导航 Controller 时,我还尝试将背景颜色设置为 .clear,但我得到的是黑色背景。有什么想法吗?

最佳答案

您只是忘记将演示样式移动到 UINavigationController

navContr.modalPresentationStyle = .custom

关于ios - UINavigationController - 使用 UIBlurEffect 清除背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42422218/

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