【代码】swift 获取window。
获取当前window
class func keywindow() -> uiwindow {
if #available(ios 15.0, *) {
let keywindow = uiapplication.shared.connectedscenes
.map({ $0 as? uiwindowscene })
.compactmap({ $0 })
.first?.windows.first ?? uiwindow()
return keywindow
}else {
let keywindow = uiapplication.shared.windows.first ?? uiwindow()
return keywindow
}
}
安全区域,状态、导航、tabbar高度
static func xp_safedistancetop() -> cgfloat {
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
}
static func xp_safedistancebottom() -> cgfloat {
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
}
static func xp_statusbarheight() -> cgfloat {
var statusbarheight: cgfloat = 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
return statusbarheight
}
static func xp_navigationbarheight() -> cgfloat {
return 44.0
}
static func xp_navigationfullheight() -> cgfloat {
return uidevice.xp_statusbarheight() + uidevice.xp_navigationbarheight()
}
static func xp_tabbarheight() -> cgfloat {
return 49.0
}
static func xp_tabbarfullheight() -> cgfloat {
return uidevice.xp_tabbarheight() + uidevice.xp_safedistancebottom()
}
相关文章:
-
Windows下安装Zookeeper(图文记录每一个步骤,手把手包安装成功)…
-
-
-
-
曾经写过一篇关于RabbitMQ的Ubuntu安装教程(),当时使用的是Docker将RabbitMQ安装到虚拟机上,但是有很多小伙伴问Windows上如何进行安装RabbitMQ…
-
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论