I uploaded your sample project and was able to fix it. I will explain what the problem is.
First of all, the UINavigationBar is contained within the UINavigationController. Thus, RootViewController and TranslucentViewController use the same instance of the UINavigationBar. Perhaps this is causing confusion. Also, probably why + the appearance of WhenContainedIn: doesn't work as you expect.
To set the background image of your navigation bars throughout your application, you must use + appearance. To set the background image of a single navigation bar in the navigation controller, use -setBackgroundImagE: forBarMetrics: from UINavigationBar.
Code: in -TranslucentViewController viewWillAppear: set the background image and panel style. In the RootViewController, set the background image and panel style again. In my experience, it's best to change the navigation bar in -viewWillAppear: instead of -in viewWillDisappear: (or you need to keep track of how to change it back.)
In RootViewController
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"orangeNavigationBar.png"] forBarMetrics:UIBarMetricsDefault]; }
In TranslucentViewController
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent]; }
Oh: and just change it in this place. Not by clicking on the view controller or something else.
source share