我有一个 rootViewController
,它是一个 UITabBarController
。该控制器中存在 UIToolBar
,因为它具有对应用程序全局的 SearchBar
。在某些选项卡中,应该有特定的 UIBarButtonItems
或 UISegmentedControl
以及搜索栏。在其他选项卡中,工具栏中不应有任何内容,只有标题。
布局视图的好方法是什么?目前,根据选择的选项卡,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.
发布评论
评论(1)
简短的回答是,没有真正的好方法可以做到这一点。如果您使用标签栏控制器,标签栏将始终在屏幕底部可见。据推测,每个选项卡都是一个顶部有导航栏的 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 aUINavigationController
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 thetoolbarItems
property to return the items that should appear in each of the child view controllers. You'll just need to settoolbarHidden
toNO
on theUINavigationController
, and you're good to go.