【发布时间】:2017-02-23 17:15:48
【问题描述】:
我在UIViewController 中使用UIBlurEffect,它以.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的结果:
问题是当我将视图控制器嵌入到 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,但我得到了黑色背景。有什么想法吗?
【问题讨论】:
-
您找到解决方案了吗?
标签: ios swift swift3 uinavigationcontroller uiblureffect