导航栏重新启动应用程序后收缩

时间:2014-01-25 03:26:47

标签: ios objective-c resize navigationbar shrink

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

我能够使用以下代码制作它,我的问题是,当我按下主页按钮关闭应用程序并重新打开它时,我的导航栏缩小,在链接图像上它有88px并且在重新启动44px之后,所以它弄乱了我的布局。

以下是我在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];
    }

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

你永远不应该改变导航栏框架。相反隐藏导航栏,创建自定义视图并将其添加到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];