1.获取状态栏的高度
let statusBarHeight = UIApplication.shared.statusBarFrame.height;
使用公共的文件宏定义,用于屏幕适配:
let statusBarHeight = UIApplication.shared.statusBarFrame.height;
//导航栏高度
let navigationHeight = (statusBarHeight + 44)
//tabbar高度
let tabBarHeight = (statusBarHeight == 44 ? 83 : 49)
//顶部的安全距离
let topSafeAreaHeight = (statusBarHeight - 20)
//底部的安全距离
let bottomSafeAreaHeight = (tabBarHeight - 49)
2.获取底部的底部的安全距离
iPhone X手机为34,iPhone X以前手机为0
let bottomSafeAreaHeight = UIApplication.shared.windows.last?.safeAreaInsets.bottom ?? 0.0;
使用公共的文件宏定义,用于屏幕适配:
//底部的安全距离
let bottomSafeAreaHeight = UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0.0
//顶部的安全距离
let topSafeAreaHeight = (bottomSafeAreaHeight == 0 ? 0 : 24)
//状态栏高度
let statusBarHeight = UIApplication.shared.statusBarFrame.height;
//导航栏高度
let navigationHeight = (bottomSafeAreaHeight == 0 ? 64 : 88)
//tabbar高度
let tabBarHeight = (bottomSafeAreaHeight + 49)
网友评论