问题描述
UINavigationBar * navigationBar = [UINavigationBar外观];
[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];
一切都很好,但我有一个奇怪的Bug,当我打开iOS6的Facebook共享表并打开观众列表(或专辑列表无关紧要):导航栏使用我的top_bar-Image呈现。
请参阅以下屏幕:
< - 没有我的外观改变的正常
< - 随着我的外观变化越来越多
任何想法如何避免这个错误?
谢谢! :
使用 UIAppearance
意味着它们在任何地方都会生效。这可能非常有用或非常讨厌。
您可以尝试解决此问题的一种方法是使用
[[UINavigationBar appearanceWhenContainedIn ... ...
,您可以制作导航栏的自定义子类,并将您的外观更改仅适用于:
[[MYNavigationBar外观] setSomething:aThing];
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 changes
Any idea how avoid this bug?Thanks! :)
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];
这篇关于UINavigationBar外观和Facebook-Sheet Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!