ios - 重新启动应用程序后导航栏缩小

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

我该如何解决这种行为?

最佳答案

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

关于ios - 重新启动应用程序后导航栏缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21346224/

相关文章:

ios - 找不到符号 : _NSUserActivityTypeBrowsingWeb

ios - 将所有对象(保留它们的关系)从一个 Realm 复制到另一个 Realm

iphone - 我必须提供哪些选项才能提供允许对 UITableView 进行排序的功能?

C++ list.unique() 会调整列表的大小吗?

c - 位图文件的填充

c# - 最佳调整大小和/或裁剪逻辑

ios - 资源文件未在本地化中显示

objective-c - 比较数组中的字符串和另一个字符串

ios - 使用 NSVlaueTransformer 将图像转换为 NSData 时出错

objective-c - 点击按钮时显示 UIPickerView