简体   繁体   English

iOS扩展中如何获取状态栏高度

[英]How to get the status bar height in iOS Extension

I can get the status bar from UIApplication in normal app by我可以通过以下方式从普通应用程序中的 UIApplication 获取状态栏

[UIApplication sharedApplication].statusBarFrame

But we cannot access UIApplication from Extension.Is there a way to find get the statusbar in share?但是我们无法从 Extension 访问 UIApplication。有没有办法找到 get get the statusbar in share?

You may use safeAreaLayoutGuide to calculate layout frame. 您可以使用safeAreaLayoutGuide来计算布局框架。 eg, 例如,

viewController.view.safeAreaLayoutGuide.layoutFrame.minY

Alternate Option:备选方案:

If you're using a view controller with NavigationBar , you can consider its y position as the StatusBar height, in case safeAreaLayoutGuide and window?.windowScene?.statusBarManager?.statusBarFrame.height options were not available or usable.如果您将视图 controller 与NavigationBar一起使用,则可以将其y position 视为StatusBar高度,以防safeAreaLayoutGuidewindow?.windowScene?.statusBarManager?.statusBarFrame.height选项不可用或不可用。

let statusBarHeight = navigationController?.navigationBar.frame.origin.y ?? 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM