views:

4593

answers:

7

Hi, I am using a navigation controller, and I have the style set to :

navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

But when I run my program, the navigation controller looks like it is on top of a white background, not my background. When I push a controller, left or right, all my view, the current one, shifts to the top exactly the size of the navigation bar. And it is there where I can see my background through the navigation controller bar. Any ideas? When my barStyle is set to opaque, everything looks fine. I was thinking on setting my view frame a negative 'y' value, but I think there should a more elegant way.

+2  A: 

I believe the UINavigationController assumes that your controller view frames don't include the area beneath the navigation bar.

UIBarStyleBlackTranslucent is more often used for UIToolbar, so Apple probably didn't make it easy to use it nicely with UINavigationBar. You'll probably need to abandon the UINavigationController, or start hacking the frames (careful with rotations), if you want to reliably render under the bar area.

Also, if your intention is to hide the navigation bar after a few seconds, you'll have a much easier time if you make it fade out (like the Photos app) instead of trying to slide it up (like Mobile Safari). Trust me on that one... that took me a lot of time to learn the hard way.

Marco
A: 

The navigation controller offsets the coordinate sytem of all it's subviews so they draw below the navigation bar.

Extend your view's frame into the negative y domain for it to draw under the navigation bar.

lajos
Tried this, with no luck. I will continue testing, as this seems to be the obvious way.
Carlos Hernandez
This doesn't work because UINavigationController *really* wants to manage the size of views it manages on it's own, so it tends to reset frames at will. You can try resetting the frame of the view you intend to slide under *after* that view is on screen, but Your Mileage May Vary.
rpj
A: 

If you set your nav controller's navigationBar to transparent in your App delegate early enough (It worked for me before adding the nav controller to the window), it will automatically shift your view up underneath the navigation bar.

Unfortunately it does not also shift your view underneath the status bar. Sad, it looks like you need to implement your own version of UINavigationController. Luckily, it's not too bad as UINavigationBar is pretty reusable.

Colin Barrett
Well, maybe the solution is that, implement my own version.
Carlos Hernandez
+1  A: 

I had the same problem, and I solved it by making the background of the root view the same as my view. The white area behind the navigation bar turned out to be the root view.

Can Berk Güder
+1  A: 

You need to set the barstyle in your info.plist file for it offset everything correctly.

However, I haven't tried it since the 2.1 f/w was released, but when I tried this in 2.0 I found that the setting was lost after a rotation from portrait to landscape.

Phil Nash
A: 

I ran into this same problem (in 3.1.3) and while you can't set the bar style after the navigationBar has already been setup you CAN set the tintColor and translucent values whenever you like:

    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationController.navigationBar.translucent = YES;

Will create the 'blackTranslucent' bar, I change the navigationBar look when I push certain view controllers onto the stack.

Shizam
A: 

try to use this, may be it will helpful.

_topToolBar.barStyle = UIBarStyleBlackTranslucent;

_topToolBar.alpha = 0.3;

Harpreet