我在一个以.crossDissolve过渡风格呈现的UIViewController中使用UIBlurEffect。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,但得到的是黑色背景。有什么想法吗?
发布于 2017-02-24 02:11:14
您只是忘了将演示文稿样式移动到UINavigationController
navContr.modalPresentationStyle = .custom发布于 2017-02-24 01:21:23
使用导航控制器,您无法实现您想要的功能。只有带有OverCurrentContext的模态演示,支持从一个视图控制器转换到另一个具有清晰或半透明背景的视图控制器。
如果您希望此视图控制器的背景模糊,则使用带有“自定义(或当前上下文以上)”的模式表示来呈现此视图控制器。
或者试试这个:
func showLiveDealsCategory(sender:UITextField){
let catSelection = LiveDealCategorySelection()
let navContr = UINavigationController(rootViewController: catSelection)
navContr.modalPresentationStyle = .custom // << Mark this update
catSelection.modalPresentationStyle = .custom
catSelection.modalTransitionStyle = .crossDissolve
self.present(navContr, animated: true, completion: nil)
}https://stackoverflow.com/questions/42422218
复制相似问题