开发者

UINavigationBar with a static image

开发者 https://www.devze.com 2022-12-12 04:14 出处:网络
Addi开发者_StackOverflow中文版ng 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

Addi开发者_StackOverflow中文版ng 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


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.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号