简体   繁体   English

Swift:UITabbarController覆盖而不覆盖情节提要中的TabBar

[英]Swift: UITabbarController Overlay without covering TabBar in Storyboard

I have a UITabBarController with a custom center UIButton. 我有一个带有自定义中心UIButton的UITabBarController。 I created this Button programmatically. 我以编程方式创建了此Button。 I want a overlay(View) to appear whenever (No matter which tab you are on) you press this button. 我希望每当您按下此按钮时(无论您在哪个选项卡上)都显示覆盖(视图)。 But since I am just starting getting into Swift etc. I would like to design this overlay in the main.storyboard but I can't add a View to the existing UITabBarController ViewController. 但是由于我只是刚开始接触Swift等。我想在main.storyboard中设计此叠加层,但无法将View添加到现有的UITabBarController ViewController中。 I already added the addTarget to the Button so that I can call a method to show or hide the overlay. 我已经将addTarget添加到Button中,以便可以调用一种方法来显示或隐藏覆盖。

It would be awesome if you could help me figure this out. 如果您能帮助我解决这个问题,那就太好了。

Thanks 谢谢

You should implement like this way. 您应该像这样实现。

class MainTabbarViewController: UITabBarController {

    let viewTabbar : ViewForTabbar!
    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.        
    viewTabbar = Bundle.main.loadNibNamed("ViewForTabbar", owner: nil, options: nil)?[0] as! ViewForTabbar
    viewTabbar.frame = CGRect(x: 0, y: self.view.bounds.height - 50, width: self.view.bounds.width, height: 50)
    viewTabbar.tag = 100
    viewTabbar.delegate = self

    viewTabbar.initTabbar()
    self.view.addSubview(viewTabbar)
    }
}

This way you can make customized TabbarController 这样您可以制作自定义的TabbarController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM