2017-08-14 38 views
0

這裏的展示這一問題的GIF:如何防止狀態欄在UIImagePickerController覆蓋整個屏幕之前消失?

enter image description here

當呈現UIImagePickerController這樣的:前圖片選擇器全屏

self.present(imagePicker, animated: true, completion: nil)

狀態欄消失。

我遇到的問題是,隨着狀態欄消失在一片煙霧中,導航欄跳起來,佔據狀態欄留下的空白處。當UIImagePickerController被解僱時,狀態欄顯示在合適的位置。

我目前沒有以任何方式定製狀態欄,都是默認的。

有沒有辦法阻止UIStatusBar消失,至少要等到UIImagePickerController動畫完成?

+0

你想在相機屏幕上顯示狀態欄嗎? –

+0

不,我不想在拍照時使用狀態欄。我只是希望它在演示動畫期間保持原位,而不是在動畫開始時消失。 我希望我在呈現'UIImagePickerController'之前擁有的視圖與其上的完全相同(我的vc與狀態欄)和'UIImagePickerController'。 –

+0

好的,抱歉,我現在明白了。 這是一個默認行爲,也它是由蘋果UI準則 建議「考慮顯示全屏媒體時臨時隱藏狀態欄。當用戶試圖把重點放在媒體的狀態欄可以分散注意力。暫時隱藏這些元素以提供更加身臨其境的體驗。例如,Photos應用程序會在瀏覽全屏照片時隱藏狀態欄和其他界面元素。「 [1] https://developer.apple.com/ios/human-interface-guidelines/ui-bars/status-bars/ –

回答

1

如果您希望狀態欄留在屏幕的頂部,您應該創建一個自定義窗口並手動應用動畫。這可能有所幫助:

var newWindow = UIWindow() 
let newController = viewControllerToPresent() 
var animationDuration = 0.4 // or whatever you want. 
// setting newController as root of new window. 
self.window.rootViewController = newController 
self.window.windowLevel = UIWindowLevelStatusBar 
self.window.backgroundColor = .clear 
self.window.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) 
self.window.isHidden = false 

UIView.animate(withDuration: animationDuration) { 
    self.window.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) 
} 
相關問題