使用 UIToolBar 和 UITabBarController 查看层次结构

发布于 2024-12-07 04:40:53 字数 529 浏览 0 评论 0 原文

我有一个 rootViewController ,它是一个 UITabBarController 。该控制器中存在 UIToolBar,因为它具有对应用程序全局的 SearchBar。在某些选项卡中,应该有特定的 UIBarButtonItemsUISegmentedControl 以及搜索栏。在其他选项卡中,工具栏中不应有任何内容,只有标题。

布局视图的好方法是什么?目前,根据选择的选项卡,rootViewController 中的主工具栏要么按原样使用,要么添加一个 UISegmentedControl,完全隐藏并替换为另一个 viewController有自己的工具栏等。对我来说,我认为在自己的选项卡中存在的每个 viewController 都可以有自己的工具栏,并引用全局功能,而不是隐藏/显示不同的工具栏。

抱歉,如果这是一个复杂的问题。只是想知道人们是否有这方面的经验。谢谢。

I have a rootViewController that is a UITabBarController. A UIToolBar is present in that controller since it has a SearchBar that is global to the app. In certain tabs, there should be specific UIBarButtonItems, or UISegmentedControl, along with the searchBar. In other tabs, there should be nothing in the toolBar, just a title.

What is a good way to lay out the view? Currently based on what tab is selected, the main toolBar from the rootViewController is either used as it is, have a UISegmentedControl added to it, hidden completely and replaced with another viewController that has its own toolbar, etc. To me, I'm thinking that each viewController that is present in its own tab can have its own ToolBar, and reference the global functionality, vs hiding/showing different toolbars.

sorry if this is a convoluted question. Just wondering if people had experience with this. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2024-12-14 04:40:53

简短的回答是,没有真正的好方法可以做到这一点。如果您使用标签栏控制器,标签栏将始终在屏幕底部可见。据推测,每个选项卡都是一个顶部有导航栏的 UINavigationController。此布局中没有合适的位置放置工具栏按钮。

更好的设计可能是放弃 UITabBarController 并使用 UINavigationController 作为根视图控制器。您可以使用表视图,其中包含应用程序的每个视图的项目,而不是选项卡。然后,屏幕底部将有空间放置工具栏。事实上,UINavigationController 支持在底部设置一个工具栏。您只需覆盖 toolbarItems 属性返回应出现在每个子视图控制器中的项目。您只需在 UINavigationController 上将 toolbarHidden 设置为 NO 即可。

The short answer is that there isn't really a good way to do this. If you're using a tab bar controller, the tab bar will always be visible along the bottom of your screen. Presumably each tab is a UINavigationController with a navigation bar at the top. There's not an appropriate place to put toolbar buttons in this layout.

A better design could be to abandon the UITabBarController and use a UINavigationController as your root view controller. Instead of tabs, you can have a table view with an item for each view of your application. Then you'll have room for a toolbar at the bottom of the screen. In fact, UINavigationController supports having a toolbar at the bottom. You just override the toolbarItems property to return the items that should appear in each of the child view controllers. You'll just need to set toolbarHidden to NO on the UINavigationController, and you're good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文