I got a problem, I need to build something similar to this, where the red bar is a UIImageView and the blue bar is the navigation bar: http://imagizer.imageshack.us/v2/800x600q90/30/iqtt.png

I was able to make it with the following code, my problem is that when I press home button to close the app and reopen it, my navigation bar shrinks, on the link image it has 88px and after relaunch 44px, so it mess with my layout.

Here is the code I've used on viewDidAppear:

    - (void)viewDidAppear:(BOOL)animated {
         [super viewDidAppear:animated];
         self.navigationController.view.frame = CGRectMake(0, 0, 320, 568);
         self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 88);

         v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
         UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(33, 5, 255, 29)];
         [img setImage:[UIImage imageNamed:@"top-logo"]];
         [v addSubview:img];
         [self.navigationController.navigationBar addSubview:v];
    }

How could I fix that behavior?

有帮助吗?

解决方案

you should never change navigation bar frame.Instead hide the navigation bar ,and create your custom view and add it to top of self.view.

 self.navigationController.navigationBarHidden =YES;
 self.view.frame = CGRectMake(0, 0, 320, 568);;

 // v is our total 88px height navigation bar
 v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 88)];
 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(33, 5, 255, 29)];
 [img setImage:[UIImage imageNamed:@"top-logo"]];
 [v addSubview:img];

 UIView *navigationBar = //create nav bar with buttons of height 44px
 [v addSubview:navigationBar];

[self.view addSubview:v];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top