我正在用这样的代码创建我的 UINavigationBar:
// init and add root navigation controller to view
_rootNavigationController = [[UINavigationController alloc] init];
[_rootView.contentContainer addSubview:_rootNavigationController.view];
_rootNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
然后在某个 UIViewController 中,我希望 UINavigationBar 有一个清晰的背景,所以我使用这段有效的代码:
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.topItem.title = @"";
[navBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[navBar setShadowImage:[UIImage new]];
[navBar setTranslucent:YES];
[navBar setTintColor:[[AVOThemeManager sharedTheme] contentBackButtonColor]];
一旦用户通过按返回离开此页面,我想将我的 UINavigationBar 返回到它原来的样子,所以我正在尝试这样做:
- (void)viewDidDisappear:(BOOL)animated {
UINavigationBar *navBar = self.navigationController.navigationBar;
[navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[navBar setShadowImage:nil];
[navBar setBarStyle:UIBarStyleBlackTranslucent];
[navBar setTranslucent:YES];
}
但这似乎行不通。我也不想将 UINavigationBar 设置为一个新实例,然后设置属性,因为它有一个添加到根导航 Controller 中的全局按钮, subview Controller 不知道。
还有什么我可以尝试的吗?
最佳答案
发帖后,马上就找到了答案。基本上,我不应该使用 viewDidDisappear,而应该使用 viewWillDisappear,它起作用了。
关于ios - 不同 View 的不同 UINavigationBar 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25431634/