Navigation Bar Shrinking after relaunching app

守給你的承諾、 提交于 2019-12-24 03:54:12

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/21346224/navigation-bar-shrinking-after-relaunching-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!