Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapview Affecting UINavigationBar and TabBar Appearance

I have a MKMapView in a UIView. Never any issues until iOS7. My colors for UITabbar and UINavigationBars are set by UIAppearance Protocol.

For some reason whenever the MKMapView is initiated, all my tabbars and navbars reset, ignoring the barTintColor setting of my appearance class. All other settings from UIAppearance seem to remain such as title attributes and barItem attributes. Only barTintColor goes out.

One more thing. This only happens on iPhone 4 and iPhone4S, not on iPhone 5. It does not happen on the simulator either. Was not an issue in iOS6 at all.

I can find no other cause for the reset. I went through and commented out just about all the goings on and it had no effect either way.

If I delete the MKMapView control, no reset of colors. If I then go on to present another, altogether different view with an MKMapView, again the colors reset.

I am looking for ideas of what else to check, what kind of settings or methods could possibly cause this behavior. Give me some stuff to eliminate, I am stuck.

Additional Info:

Now thinking this may be a bug. I put a line to hard code the color of the navbar to an arbitrary color in ViewDidLoad just to see what is going on.

UINavigationBar *bar = self.navigationController.navigationBar;
[bar setBarTintColor = [UIColor GreenColor];

I put a break on the next line. Inspecting bar, the color seems to be set.

On iPhone4 or 4S, bar does not turn green. On iPhone5 and simulator, bar turns green.

Some more items I have discovered. The color is not changing. It appears the visibility is. Yet, reading the alpha of the color and of the bar returns 1.0 both.

So color is correct.

Translucency is yes.

Alpha is 1.0.

And yet the bar is completely clear, no color, no tint.

I think I will file this officially as a bug. I made a test viewController with only a MKMapview. No code, no delegate, no annotations. Presented that in place of my proper controller. The same thing happened.

What I need right now is a workaround. I just cannot tell what is changing. When I inspect the properties of the navigation bar, everything is correct. Tint color, translucency, bar Tint Color, alpha value. So far as I can tell, the thing should be displaying as intended.

Can anyone tell me other properties or methods that could make the background of the navigation bar completely transparent?

like image 818
Dean Davids Avatar asked Sep 29 '13 16:09

Dean Davids


1 Answers

After some more searching I see that there are some related threads in the developer forums and this issue has been noted for some time. I expect I will receive response that my bug report is a dupe. In the meantime, I believe I have come up with a workaround.

What I came up with is a sequence of setting

self.navigationController.navigationBar.translucent = NO;
self.tabBarController.tabBar.translucent = NO;

when the view containing a MKMapView is loaded and then setting it YES in viewDidAppear. I set to NO again on viewWillDisappear. Then the returning viewController must reset to translucent again in its viewDidAppear.

I used a series of NSNotification posts in the View Controllers with the maps. I subclassed my navigation controllers and tab bar to make them listen for the notification and respond by toggling their own bar translucency property.

Managed to get it done. With a small amount of code, but it is an awful lot of activity for no good reason. Would more like to see this fixed ASAP.

like image 62
Dean Davids Avatar answered Oct 27 '22 07:10

Dean Davids