简体   繁体   English

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

[英]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.

相关问题 Swift:如何使用“快速操作”从AppDelegate访问某个TabBar标签? - Swift: How to access a certain TabBar tab from AppDelegate with Quick Actions? 如何在 tabBar 中打开另一个 tabItem controller 在 swift 4 - How to switch on another tabItem in tabBar controller in swift 4 如何正确快速地从另一个控制器访问一个控制器变量和方法? - How to access one controller variable and methods from other controller in swift correctly? 将数据从Tabbar控制器传递到Swift和XCode中的视图控制器 - pass data from tabbar controller to view controller in swift and xcode 从Tabbar Controller跳回到导航控制器-Swift 4 - Jump back to navigation controller from tabbar controller - swift 4 如何将标签栏控制器从一个标签栏推到另一标签栏控制器 - How to push tabbar controller from one tabbar to another tabbarcontroller 如何快速从故事板中的 didSelectRowAt indexPath 打开视图标签栏控制器? - How to open view tabbar controller from didSelectRowAt indexPath within storyboard in swift? 从appdelegate访问Tabbar视图控制器的子控制器 - Access child controller of Tabbar view controller from appdelegate 如何在Swift ios的Tabbar Controller中设置rootview并在每个View Controller中显示Tabbar? - How to set rootview in tabbar controller and show tabbar in each view controller in swift ios? Swift:通过TabBar和导航控制器以编程方式从一个视图过渡到另一个视图 - Swift: Programmatically transitioning from 1 view to another via a TabBar and Navigation Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM