如下图所示,从window.root到tabBarController,tabBarController的第一个子节点是导航控制器,问题出现在导航控制器的根视图控制器中。
问题在于:
当我调用底部标签栏显示和隐藏时,布局问题。一个空白栏,其大小为标签栏,很糟糕。
以下是代码:
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
}
}
我认为尺寸检查员的布局选项可能很重要。我没有找到任何线索。
任何有用的提示都非常受欢迎。
答案 0 :(得分:0)
当值等于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
}