Reputation: 2155
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!!!
Upvotes: 2
Views: 2465
Reputation: 90
Call layoutSubviews() after your call to hide or show the navigation bar:
[self.navigationController.view layoutSubviews];
Upvotes: 0
Reputation: 1368
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)
}
}
Upvotes: 2
Reputation: 722
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)
}
Upvotes: 0
Reputation: 2155
Ok , I find the answer:
self.navigationController.view.backgroundColor = [UIColor redColor];
Upvotes: 14
Reputation: 3631
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];
}
Upvotes: 7