我为导航栏设置了自定义高度,状态栏也隐藏了:
override func viewDidLayoutSubviews() {
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: 60)
}
override var prefersStatusBarHidden: Bool {
return true
}
我也尝试过:
override func viewDidAppear(_ animated: Bool) {
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 40)
}
但重新启动应用后,顶部有一种填充:
我看到了answer:
override func viewWillAppear(_ animated: Bool) {
let bounds = self.navigationController!.navigationBar.bounds
navigationController?.isNavigationBarHidden = true
let navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: bounds.width, height: 60))
self.view.addSubview(navBar);
let navItem = UINavigationItem(title: "Add");
let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: nil, action: #selector(addNewRecipe(_:)));
navItem.rightBarButtonItem = doneItem;
navBar.setItems([navItem], animated: false);
view.addSubview(navBar)
}
除了隐藏导航栏并以编程方式编写每个导航项外,还有其他方法吗?
谢谢!