views:

377

answers:

2

Adding an image to a UINavigationItem's titleView is pretty trivial, but when I push a new view on the stack it animates the UINavigationItem sliding off to the left, along with the titleView, and loads a new UINavigationItem.

I can think of a number of ways to go about making that image stay put, but they all seem pretty hacky. Is there a normal way of doing this that I can't find? Following is code for adding an image to my view controller's UINavigationItem:

UIImage *tImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logo_topbar" ofType:@"png"]];
UIImageView *tImageView = [[UIImageView alloc] initWithImage:tImage];
self.navigationItem.titleView = tImageView;
[tImage release];
[tImageView release];

Thanks guys/gals

+1  A: 

You can add the same titleView to all UIViewControllers that you would like it to appear on, I would guess however that this would let the ImageView be animated out to the left and a new identical one coming in from the right.

The only way I see is to add the UIImageView like this:

[self.navigationController.view addSubview:tImageView];

or try this

[self.navigationController.navigationBar addSubview:tImageView];
Felix
+2  A: 

I imagine you could embed the entire view into a super-view, with the static image underneath your existing UI. You can then make the header in the UINavigationItems transparent, so the buttons will slide around over the image, but the image will stay put.

Matt B.
This solution sounds interesting, but I'm not convinced it's the best method. Are you talking about making the entire navigation bar transparent except for the buttons? And then basically place a screenshot of the bar + logo underneath it? Because if you just made the UINavigationItem over the underlying image transparent, it would be moved during transitions as well, causing an even more bizarre windowing effect on the underlying logo.
DougW
I think this is a little vague, but I'm going to go ahead and accept it because I think a variation of this method is the only way without an entirely custom nav bar. To avoid strange windowing you would probably have to at least subclass the entire bar and manage the layout of sub-elements yourself.
DougW