我正在以UIBlurEffect转换样式呈现的UIViewController中使用.crossDissolve。 UIViewController的视图中添加了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的结果:

ios - UINavigationController-使用UIBlurEffect清除背景-LMLPHP

问题是当我将视图控制器嵌入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
        }
  }

并且我还尝试在实例化导航控制器时将背景色设置为.clear,但背景为黑色。任何的想法?

最佳答案

您只是忘了将演示文稿样式移至UINavigationController

navContr.modalPresentationStyle = .custom

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

10-16 19:23