[英]How to access tabbar height from other controller in swift?
I want to attach a view from a specific controller (MyController) just above the tabbar but my problem is how would I calculate the height of the tabbar from MyController so that I could give y position to my custom view.我想在标签栏上方附加一个来自特定 controller (MyController) 的视图,但我的问题是如何从 MyController 计算标签栏的高度,以便我可以将 y position 提供给我的自定义视图。 I am trying to achieve with statusBarFrame but it's not working.
我正在尝试使用 statusBarFrame 来实现,但它不起作用。 If anybody has some idea please help me out.
如果有人有任何想法,请帮助我。
let timerView = UINib(nibName: "WorkoutTimer", bundle: nil).instantiate(withOwner: nil, options: nil).first as? WorkoutTimer
let window = UIApplication.shared.windows.last
if let timerView = timerView {
let screenSize = UIScreen.main.bounds
let screenHeight = screenSize.height
let screenWidth = screenSize.width
let statusbarHeight = UIApplication.shared.statusBarFrame.height
let yPosition = screenHeight - ((statusbarHeight) + 50)
timerView.frame = CGRect(x: 0, y: yPosition, width: screenWidth, height: 50)
window?.addSubview(timerView)
}
directly take the y position of tabBarController?.tabBar.frame.origin.y and add your timerview frame height直接取 tabBarController?.tabBar.frame.origin.y 的 y position 并添加您的 timerview 框架高度
if let timerView = timerView {
let yPosition = self.tabBarController?.tabBar.frame.origin.y - 80
timerView.frame = CGRect(x: 0, y: yPosition, width: UIScreen.main.bounds.size.width, height: 50)
window?.addSubview(timerView)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.