【发布时间】:2014-08-21 16:45:44
【问题描述】:
我正在用这样的代码创建我的 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 设置为新实例,然后设置属性,因为它有一个全局按钮,该按钮添加到根导航控制器中,子视图控制器不知道。
还有什么我可以尝试的吗?
【问题讨论】:
标签: ios objective-c uinavigationbar appearance