我正在制作一个 cocoa 库,我需要获取状态栏高度,我使用以下代码:
let statusBarHeight = UIApplication.shared.isStatusBarHidden ? CGFloat(0) : UIApplication.shared.statusBarFrame.height
我在另一个项目中使用 lib,一切正常,但如果我在应用程序扩展中使用 Lib,我得到:
'shared' is unavailable: Use view controller based solutions where appropriate instead
如何测试我是否在扩展内?或者如何在不使用共享的情况下获得状态高度?
谢谢!
最佳答案
如果您的目标是 iOS 11,请使用 View Controller 的 topLayoutGuide.length
,或 View Controller 的 View 的 safeAreaInsets.top
。这些值将考虑任何导航栏
关于ios - 不使用 UIApplication.shared 获取状态栏的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46774872/