因为业务需求,通常会在viewWillAppear下执行self.navigationController.navigationBarHidden = YES/NO

然后就会看到navigationBar出现各种问题:navigationItem重叠、标题重叠、失去动画等

其实正确的姿势应该是

1
2
3
4
5
6
7
8
9
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}

这样,就不会有问题了

PS:在最新的iOS10里,apple似乎对UINavigationBar进行了重构,这个问题似乎只会存在于iOS10以下的系统.