尝试使用隐藏的 UINavigationBar 实现持久 UIToolBars 似乎是在操作未记录的 View 类
我在窗口的顶部和底部都有一个工具栏。我也在使用 UINavigationController。所以我也想隐藏导航栏。我发现了这个问题:
Persistent UIBarButtonItem in UIToolbar?
所以在应用程序委托中我做了:
[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中链接。这是您可以看到的:
- 状态栏。好的。
- 一半顶部工具栏
- 导航栏遮盖了顶部工具栏的下半部分和一些已加载视图。
- 您的第一个视图,顶部的一小部分被导航栏隐藏。
- 底部工具栏就OK了。
setNavigationBarHidden 似乎只是将导航栏移开。我可以通过在导航栏上显式设置 hide=YES (或 UINavigationBar 上的类别并覆盖drawRect)来实现我想要的。
导航控制器上的视图显然是一个 UILayoutContainerView。这似乎没有记录。
那么:
- 这是一个好方法吗?可能会被拒绝吗?
- 为什么我会出现与导航栏重叠的行为?
I have a toolbar at the top and at the bottom both set in the window. I am also using a UINavigationController. So I want to hide the nav bar as well. I found this question:
Persistent UIBarButtonItem in UIToolbar?
So in the app delegate I did:
[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];
The toolbars are linked in IB. This is what you can see:
- The status bar. OK.
- Half the top toolbar
- The nav bar which obscures the bottom half of the top toolbar and a bit of the loaded view.
- Your first view with a small portion at the top hidden by the nav bar.
- The bottom toolbar is OK.
setNavigationBarHidden just seems to move the nav bar out of the way. I can achieve what I want by explicitly setting hidden=YES on the nav bar (or a category on UINavigationBar and overriding drawRect).
The view on the nav controller is apparently a UILayoutContainerView. This appears to be undocumented.
So:
- Is this a good method? May it get rejected?
- Why do I get this overlapping behaviour with the nav bar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这个解决方案有效(不重叠导航栏)
I found this solution works (without overlapping the navigation bar)