问题
I use the following code in my appdelegate:
UINavigationBar *navigationBar = [UINavigationBar appearance];
[navigationBar setBackgroundImage:[[UIImage imageNamed:@"top_bar"] stretchableImageWithLeftCapWidth:5 topCapHeight:5] forBarMetrics:UIBarMetricsDefault];
[navigationBar setBackgroundImage:[[UIImage imageNamed:@"top_bar_scape"] stretchableImageWithLeftCapWidth:5 topCapHeight:5] forBarMetrics:UIBarMetricsLandscapePhone];
Everything works fine but i got a weird Bug, when i open the iOS6 Facebook Sharing-Sheet and open the audience-list (or album list doesnt matter): The Navigationbar is rendered with my top_bar-Image. See screens below:
<- Normal without my appearance changes <- Buggy with my appearance changesAny idea how avoid this bug? Thanks! :)
回答1:
Appearance changes made using the UIAppearance
methods are global - meaning they take effect everywhere. This can be very very helpful or very very annoying.
One way you could try to fix this problem is either use
[[UINavigationBar appearanceWhenContainedIn:...
or, you could make a custom subclass of the navigation bar, and have your appearance changes applied only to it:
[[MYNavigationBar appearance] setSomething:aThing];
回答2:
Appearance settings are applied to all the controls that are displayed after you define your settings. So in your case every navigation bar will use your background image. You can fix your problem by changing the appearance settings (black color) before you push the view controller that should have the black nav bar and set them back before you pop the view controller with the black nav. I had a similar problem in on of my projects and what I mentioned above solved the problem.
P.S Sorry for any spell mistakes and for the lack of source code, i'm on the road and i'm typing from my phone ;)
来源:https://stackoverflow.com/questions/16256399/uinavigationbar-appearance-and-facebook-sheet-bug