导航栏和工具栏的显示和隐藏
ViewContorller.swift文件
//视图即将可见时执行该方法
覆盖func viewWillAppear(_ animated:Bool){
//覆盖同名类方法
super.viewWillAppear(动画)
//然后显示底部工具栏
self.navigationController?.setToolbarHidden(false,animated:true)
}
2.SecondViewContorller
override func viewDidLoad(){
super.viewDidLoad()
//加载视图后进行任何其他设置。
self.title =“第二页”
self.view.backgroundColor = UIColor.purple
let btHideNavBar = UIButton(frame: CGRect(x: 40, y: 200, width: 240, height: 30))
// 设置按钮上的标题文字
btHideNavBar.setTitle("Hide navigation", for: UIControlState())
btHideNavBar.backgroundColor = UIColor.orange
btHideNavBar.addTarget(self, action: #selector(SecondSubViewController.hidNavigationBar), for: UIControlEvents.touchUpInside)
self.view.addSubview(btHideNavBar)
let btHideToolBar = UIButton(frame: CGRect(x: 40, y: 260, width: 240, height: 30))
btHideToolBar.setTitle("Hide tool bar", for: UIControlState())
btHideToolBar.backgroundColor = UIColor.orange
btHideToolBar.addTarget(self, action: #selector(SecondSubViewController.hideToolBar), for: UIControlEvents.touchUpInside)
self.view.addSubview(btHideToolBar)
}
// 隐藏顶部导航栏的方法
@objc func hidNavigationBar (){
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
// 隐藏底部工具栏的方法
@objc func hideToolBar(){
self.navigationController?.setToolbarHidden(true,animated:true)
}