UINavigationBar appearance and Facebook-Sheet Bug

心已入冬 提交于 2019-12-11 08:12:16

问题


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! :)


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!