2017-04-08 114 views
0

我的視圖控制器中有一個UISearchController,當searchBar處於活動狀態時,狀態欄變爲透明。我試過thisthis但他們都沒有工作。當searchBar處於活動狀態時,statusBar變爲透明

enter image description here

這是視圖控制器的視圖層次:

enter image description here

如何讓狀態欄半透明?

+1

試試這個:http://stackoverflow.com/a/32235444/2108547 –

+0

@DanielStorm很棘手,但這個http://stackoverflow.com/ a/34229176/689779工作。如果你發佈一個答案,我會標記它。 – Maysam

回答

0

viewDidLoad使用此解決了這個問題:

var frame = UIApplication.shared.statusBarFrame 
     frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height*3.3) 
//3.3 is a practical number 
     let statusBarView = UIView(frame: frame) 
     statusBarView.backgroundColor = sharedApplication.mainThemeColor 
     searchController.view.addSubview(statusBarView)