0
votes

I want to add a image just above the navigation bar. Here is the final result picture I want: click me

At the beginning, I think it is quite simple:

  1. Using UIBuilder add one UIImage and one UIView
  2. Add navigation bar controller to UIView as its root view

The Hierarchy I thought should like this: UIViewController->UIView->NavigationBarController.(Here the UIView is one subview of the view of UIViewController)

Below is one of the code I tried, subView is the IBOutlet of one UIView builed by UIBuilder

    UINavigationController *test;
    test=[[UINavigationController alloc]init];

    [[subView window] setRootViewController:test];
    [subView.window makeKeyAndVisible];

But after trying several times,I found it is not working.

Does anyone do the same work before? If so, please give me some suggestions.

2

2 Answers

1
votes
self.navigationController.navigationBar.frame = CGRectMake(0, //height of imageView//, self.view.bounds.size.width, 44.0f);
0
votes

CodaFi's suggestion is almost there.

Try this:

test.view.frame = CGRectMake(0, //height of imageView//, self.window.bounds.size.width, //(total height of content... e.g. 460.0f if you leave the status bar visible)-(height of imageView)//);

There is one thing to note though... The navigation controller likes to take up all the usable space on screen so sometimes it will automatically resize its view to a rect like this, {{0.0f,0.0f},{320.0f,460.0f}} after rotating the device. I have experienced this many times on the iPad. You might have to start listening for the rotation event, and reset the frame of the navigation controller's view on every rotation to one that doesn't block your image.