2017-08-14 35 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) 
} 
相关问题