SEA-106
SEA-106

Reputation: 13

Single background image for multiple UIViewControllers

I've created a simple navigation application, which alternates between two views through the use of push/popViewController. I've decided to add a background image, rather than a pattern or single colour, to both view controllers.

Is there a way to have the same backgrounds for both views, without them scrolling when the view changes? This way, it will look like the background stays still, while everything else slides over the top.

I haven't found any help on this issue, and the only idea I've come up with up to now is to attempt to use the app delegate (or, tenuously, the navigation controller) to draw the background, but my attempts to do such have all failed terribly.

Upvotes: 1

Views: 1239

Answers (2)

Yang Meyer
Yang Meyer

Reputation: 5699

You could use a "root" view controller that manages all other view controllers in your app.

  1. Create a view controller (with the background image as its view) and add it to the window.
  2. Instantiate your navigation controller and then [rootVC.view addSubview:navController.view].

Caveat: This should work, but "nesting" view controllers like this isn't really good practice. Read the discussion Abusing UIViewControllers, and search for "UIViewController Containment" for how to do it properly in iOS 5.

Upvotes: 0

Bartek
Bartek

Reputation: 1996

Maybe try to add image to application window and set background color for both viewcontrollers to clearColor.

Upvotes: 1

Related Questions