I have a app with main page is a hidden navigationbar ,and when I back from child page with navigationbar to this main page ,because I set the navigation hidden in the main page method: - (void)viewWillAppear, I found that a black box will appear with animation, how to avoid it? Thank you very much!!!
5 Answers
14
votes
7
votes
This fixes the problem without hacking the colour, which could lead to navigation controllers being the wrong colour.
Just set it to be animated in viewWillAppear :)
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
and if you go back to page with nav controller set Animation to NO
- (IBAction)backButtonClicked:(id)sender {
[self.navigationController setNavigationBarHidden:NO animated:NO];
[self.navigationController popToRootViewControllerAnimated:YES];
}
2
votes
May be this will help someone if its happening in a tabbar controller app while switching between tabs
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if self.navigationController?.visibleViewController != self {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
}
0
votes
For Swift3.0
In First ViewController
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
In Second ViewController
func backButtonPressed() {
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationController?.popViewController(animated: true)
}