重新启动应用程序后导航栏缩小 [英] Navigation Bar Shrinking after relaunching app

查看:96
本文介绍了重新启动应用程序后导航栏缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我需要构建与此类似的东西,其中红色栏是UIImageView,蓝色栏是导航栏: http://imagizer.imageshack.us/v2/800x600q90/30/iqtt.png

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

我能够使用下面的代码来实现它,我的问题是,当我按下主屏幕按钮关闭应用并重新打开它时,我的导航栏会缩小,在链接图像上它的像素为88px,重新启动后为44px,因此弄乱了我的布局.

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.

这是我在viewDidAppear上使用的代码:

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

我该如何解决该问题?

推荐答案

永远不要更改导航栏框架.相反,请隐藏导航栏,并创建自定义视图并将其添加到self.view的顶部.

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

这篇关于重新启动应用程序后导航栏缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆