let kStatusBarHeight : CGFloat = UIDevice.vg_statusBarHeight()
let kStatusBarSpaceX : CGFloat = UIDevice.vg_safeDistanceTop()
let kTopBarHeight : CGFloat = UIDevice.vg_navigationBarHeight()//44
let kNavigationBar64 : CGFloat = UIDevice.vg_navigationFullHeight()
let kBottomBarHeight : CGFloat = UIDevice.vg_tabBarFullHeight()
let kBottomBarRealHeight : CGFloat = UIDevice.vg_tabBarHeight()//49
let kTabbarSafeBottomMargin : CGFloat = UIDevice.vg_safeDistanceBottom()
extension UIDevice {
/// 顶部安全区高度
static func vg_safeDistanceTop() -> CGFloat {
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let window = windowScene.windows.first else { return 0 }
return window.safeAreaInsets.top
} else if #available(iOS 11.0, *) {
guard let window = UIApplication.shared.windows.first else { return 0 }
return window.safeAreaInsets.top
}
return 0;
}
/// 底部安全区高度
static func vg_safeDistanceBottom() -> CGFloat {
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let window = windowScene.windows.first else { return 0 }
return window.safeAreaInsets.bottom
} else if #available(iOS 11.0, *) {
guard let window = UIApplication.shared.windows.first else { return 0 }
return window.safeAreaInsets.bottom
}
return 0;
}
/// 顶部状态栏高度(包括安全区)
static func vg_statusBarHeight() -> CGFloat {
var statusBarHeight: CGFloat = 0
if #available(iOS 13.0, *) {
let scene = UIApplication.shared.connectedScenes.first
guard let windowScene = scene as? UIWindowScene else { return 0 }
guard let statusBarManager = windowScene.statusBarManager else { return 0 }
statusBarHeight = statusBarManager.statusBarFrame.height
} else {
statusBarHeight = UIApplication.shared.statusBarFrame.height
}
return statusBarHeight
}
/// 导航栏高度
static func vg_navigationBarHeight() -> CGFloat {
return 44.0
}
/// 状态栏+导航栏的高度
static func vg_navigationFullHeight() -> CGFloat {
return UIDevice.vg_statusBarHeight() + UIDevice.vg_navigationBarHeight()
}
/// 底部导航栏高度
static func vg_tabBarHeight() -> CGFloat {
return 49.0
}
/// 底部导航栏高度(包括安全区)
static func vg_tabBarFullHeight() -> CGFloat {
return UIDevice.vg_tabBarHeight() + UIDevice.vg_safeDistanceBottom()
}
}
iOS开发笔记-126:swift5 对Iphone手机状态栏高度、顶部安全高度,底部安全高度的宏定义
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 手机顶部显示时间、电量等信息的叫状态栏,即statusBar有些手机比如华为在底部会有返回、回到主页面等虚拟功能键...
- Android一些设备都有上下两条bar,我们可以获取这些bar的信息。原文地址:http://www.cnblo...
- 状态栏高度 iphone 20 iphoneX 44 iphoneX 安全区域高度 34 大前端知识库收集分享 w...
- 转载简书博主:差得很远呢 的文章https://www.jianshu.com/p/c1f2a3849d6e ...
- 状态栏即statusBar,导航栏即某些手机底部有返回键的虚拟键那一栏,叫navigationBar。 1. 获取...