简体   繁体   中英

How to get the status bar height in iOS Extension

I can get the status bar from UIApplication in normal app by

[UIApplication sharedApplication].statusBarFrame

But we cannot access UIApplication from Extension.Is there a way to find get the statusbar in share?

You may use safeAreaLayoutGuide to calculate layout frame. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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