如何从 swift 中的其他控制器访问标签栏高度?

How to access tabbar height from other controller in swift?

我想在标签栏上方附加来自特定控制器 (MyController) 的视图,但我的问题是如何从 MyController 计算标签栏的高度,以便我可以为我的自定义视图提供 y 位置。我正在尝试使用 statusBarFrame 来实现,但它不起作用。如果有人有什么想法,请帮助我。

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)
    }

直接取tabBarController的y位置?.tabBar.frame.origin.y加上你的timerview frame height

 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)
    }