Swift4:标签栏布局问题,有一个空白栏

Swift4: Tab Bar layout issue, there is a blank bar

如下图,从window.root到tabBarController,tabBarController的第一个child是navigationController,问题出在navigationController的rootviewcontroller

这是问题所在:

当我调用底部标签栏显示和隐藏时,布局出现问题。空白栏,其大小与标签栏一样,很糟糕。

代码如下:

class ViewController: UIViewController {

  @IBOutlet var heading: UILabel!
  @IBOutlet var username: UITextField!
  @IBOutlet var password: UITextField!

    let tabBarViewController = UIApplication.shared.keyWindow!.rootViewController as! UITabBarController

    override func viewDidLoad() {
        super.viewDidLoad()
        username.delegate = self
        password.delegate = self
    }

  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
    tabBarViewController.tabBar.isHidden = true
  }
}


extension ViewController: UITextFieldDelegate{

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    let nextField = (textField === username) ? password : username
    nextField?.becomeFirstResponder()

    if textField.text == "1" {
        self.navigationController?.setNavigationBarHidden(false, animated: true )
        navigationController?.setToolbarHidden(false, animated: true)
        tabBarViewController.tabBar.isHidden = false
    }
    else{
        self.navigationController?.setNavigationBarHidden(true, animated: true )
        navigationController?.setToolbarHidden(true, animated: true)
          tabBarViewController.tabBar.isHidden = true
    }
    return true
}

}

我认为尺寸检查器中的布局选项可能很重要。我还没有找到任何线索。

非常欢迎任何有用的提示。

尝试在值为1时隐藏ToolBar:

extension ViewController: UITextFieldDelegate {
   func textFieldShouldReturn(_ textField: UITextField) -> Bool {
      let nextField = (textField === username) ? password : username
      nextField?.becomeFirstResponder()
      if textField.text == "1" {
          self.navigationController?.setNavigationBarHidden(false, animated: true )
          navigationController?.setToolbarHidden(true, animated: true)
          tabBarViewController.tabBar.isHidden = false
     }else{
          self.navigationController?.setNavigationBarHidden(true, animated: true )
          navigationController?.setToolbarHidden(true, animated: true)
          tabBarViewController.tabBar.isHidden = true
     }
     return true
}