2015-12-29 22 views
3

我有圖片示例,向您展示我想要的以及我現在擁有的內容。隱藏UIStatusBar,不刪除分配的空間

首先,這裏是我想要做的,從鬆弛的應用程序的例子:正常顯示狀態欄

enter image description here

但是,當你打開側抽屜,它消失了:

enter image description here

我可以在我的應用程序顯示狀態欄:

enter image description here

但是,當我隱藏它,它也隱藏幀,所以頂部空間小於前:

enter image description here

它看起來靠不住,從頂部除去空間每當側抽屜打開時,但由於菜單具有不同的背景色,因此不會隱藏狀態欄。我怎樣才能隱藏狀態欄上的文本,同時保持它的空間呢?

回答

2

我想你想要像下面這樣(在斯威夫特,部署目標爲9.0):

來隱藏它:

UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade) 
    let appFrame:CGRect = UIScreen.mainScreen().applicationFrame 

    UIView.animateWithDuration(0.3, animations: { 
     self.navigationController?.navigationBar.frame = self.navigationController!.navigationBar.bounds 
     self.view.window!.frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height); 
    }) 

要再次顯示:

let appFrame:CGRect = UIScreen.mainScreen().applicationFrame 
    UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .Fade) 

    UIView.animateWithDuration(0.3, animations: { 
     self.navigationController?.navigationBar.frame = self.navigationController!.navigationBar.bounds 
     self.view.window!.frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height-0.00001); 
    }) 

我我不確定你會遇到同樣的問題,但是當我測試代碼時,我原本沒有那個「-0.00001」,並且過渡不順利,但是這個小小的減法修正了它。不知道爲什麼。

+0

這並獲得成功。謝謝! – LulzCow

0

我無法接受的答案在斯威夫特3. iOS上的10個工作所以這裏是我想出了:

class ViewController: UIViewController { 

    override var prefersStatusBarHidden: Bool { 
     return true 
    } 

    override func viewDidAppear(_ animated: Bool) { 
     super.viewDidAppear(animated) 

     UIView.animate(withDuration: 0.3, animations: { 
      let bounds = self.navigationController!.navigationBar.bounds 
      self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + 20) 
     }) 
    } 
}