【问题标题】:Navigation Bar Shrinking after relaunching app重新启动应用程序后导航栏缩小
【发布时间】:2014-01-25 03:26:46
【问题描述】:

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

我可以用下面的代码实现它,我的问题是当我按下主页按钮关闭应用程序并重新打开它时,我的导航栏缩小,在链接图像上它有 88 像素,重新启动后是 44 像素,所以它弄乱我的布局。

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

我该如何解决这种行为?

【问题讨论】:

  • 试试 -(void)viewDidAppear{ self.navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 88);} 在 vi​​ewWillAppear 中也是如此。
  • 我已经尝试过了,但是重新启动后,它不起作用!谢谢

标签: ios objective-c resize navigationbar shrink


【解决方案1】:

您不应该更改导航栏框架。而是隐藏导航栏,并创建您的自定义视图并将其添加到 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];

【讨论】:

  • 是的,我认为这应该是唯一的方法。我会那样做,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多