gpt4 book ai didi

iphone - 尝试使用隐藏的 UINavigationBar 实现持久 UIToolBars 似乎是在操作未记录的 View 类

转载 作者:行者123 更新时间:2023-11-29 05:05:30 25 4
gpt4 key购买 nike

我在窗口的顶部和底部都有一个工具栏。我也在使用 UINavigationController。所以我也想隐藏导航栏。我发现了这个问题:

Persistent UIBarButtonItem in UIToolbar?

所以在应用程序委托(delegate)中我做了:

[window addSubview:navigationController.view];
CGRect frame = navigationController.view.frame; // What is this view???
frame.size.height -= (topToolBar.frame.size.height + bottomToolBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height);
frame.origin.y += topToolBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
navigationController.view.frame = frame;
[navigationController setNavigationBarHidden:YES];

工具栏在 IB 中链接。这是您可以看到的:

  • 状态栏。好的。
  • 顶部工具栏的一半
  • 导航栏遮挡了顶部工具栏的下半部分和一些已加载 View 。
  • 您的第一个 View ,顶部的一小部分被导航栏隐藏。
  • 底部工具栏正常。

setNavigationBarHidden 似乎只是将导航栏移开。我可以通过在导航栏上显式设置 hide=YES (或 UINavigationBar 上的类别并覆盖drawRect)来实现我想要的。

导航 Controller 上的 View 显然是一个 UILayoutContainerView。这似乎没有记录。

所以:

  • 这是一个好方法吗?会被拒绝吗?
  • 为什么我会出现与导航栏重叠的行为?

最佳答案

我发现这个解决方案有效(不重叠导航栏)

CGFloat height = [self.toolbar frame].size.height;
CGRect rootBounds = self.window.rootViewController.view.bounds;
CGRect frame = CGRectMake(0, CGRectGetHeight(rootBounds) - height, CGRectGetWidth(rootBounds), height);

[self.toolbar setFrame:frame];
[self.navigationController.view addSubview:self.toolbar];

关于iphone - 尝试使用隐藏的 UINavigationBar 实现持久 UIToolBars 似乎是在操作未记录的 View 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5439398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com