Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController - Keep Background Image Across All Views

Tags:

Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:

UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; background.image = [UIImage imageNamed:@"InfoBackground.png"]; [self.view addSubview:background]; [self.view sendSubviewToBack:background]; [background release]; 

Thanks!

like image 941
Kevin_TA Avatar asked Oct 27 '12 00:10

Kevin_TA


1 Answers

Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.

I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.

Let me know how it goes.

Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.

like image 182
Matt Mc Avatar answered Mar 11 '23 02:03

Matt Mc