我在使用UIBlurEffect
的UIViewController
中使用了.crossDissolve
過渡樣式。 UIViewController在其視圖中添加了一個collectionView,所以它們都有清晰的背景。UINavigationController - 使用UIBlurEffect清除背景
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:
問題是,當我嵌入在V一個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
實例化導航控制器,但我得到一個黑色的背景。任何想法?
不幸的是它也無法正常工作。可以使用'.clear'背景不能與'UINavigationController'一起使用 – mat
在模擬器和設備上都有一個非常類似的代碼,它包含'UINavigationController'上的'.clear',只是沒有CollectionView,在iOS10.2上運行。 – MarioBajr
我試過了,它不起作用。奇怪的! – mat