当有人隐藏/显示选项卡栏时是否有任何选项卡栏事件用于通知?
我创建的选项卡栏控制器的自定义子类中有一个导航控制器。
每当显示的控制器之一尝试隐藏或显示选项卡栏时,我想从(自定义)选项卡栏内知道。 (例如,将其 hidesBottomBarWhenPushed=YES 的 VC 推送到 Nac 控制器时)。
简而言之,我希望收到隐藏/显示选项卡栏的事件通知,但在苹果的参考资料中找不到任何内容。我尝试查看 UITabBar、UITabBarDelegate、UITabBarController 和 UITabBarControllerDelegate,但似乎都只提供与选项卡栏项目相关的功能。
提前致谢。
I have a Nav controller inside a custom subclass of Tab Bar controller that i created.
I want to know from within the (custom) Tab Bar whenever one of the displayed controllers attempts to hide or show the Tab Bar. (for example when pushing a VC that has its hidesBottomBarWhenPushed=YES onto the Nac controller).
In short i want to be notified of events hiding/showing the Tab Bar but could not find anything in Apple's reference. I tried looking at UITabBar, UITabBarDelegate, UITabBarController, and UITabBarControllerDelegate but all seem to only provide functionality related to the tab bar items.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用标签栏控制器,UIKit 会明确声明将在标签栏控制器上下文中显示的每个导航控制器实例都将位于其
viewControllers
属性中。现在,每个 UINavigationController 实例都有一个委托,它定义了一个 navigationController:willShowViewController:animated: 方法,让您知道何时将视图控制器推送到它上面。通过将标签栏控制器设置为推送到其上的每个导航控制器的委托,您可以分析被推送的视图控制器是否设置了 hidesBottomBarWhenPushed 属性,并在这种情况下生成事件。
用于隐藏选项卡栏控制器的选项卡栏的算法如下:当视图控制器被推到本身包含在选项卡栏控制器中的导航控制器上时,如果导航控制器的导航堆栈中的任何视图控制器具有 < code>hidesBottomBarWhenPushed 属性设置后,标签栏应该隐藏。
因此,当选择导航控制器并且其堆栈中的视图控制器之一设置了 hidesBottomBarWhenPushed 属性时,选项卡栏会隐藏。
If you are using a tab bar controller, UIKit explicitly states that every navigation controller instance that will be displayed in the tab bar controller's context will be among its
viewControllers
property. Now everyUINavigationController
instance has a delegate, which defines anavigationController:willShowViewController:animated:
method which lets you know when a view controller is pushed onto it.By setting your tab bar controller as the delegate of every navigation controller that is pushed onto it, you can analyze wether the view controller being pushed has the
hidesBottomBarWhenPushed
property set and generate an event when this is the case.The algorithm used to hide the tab bar controller's tab bar is as follows: when a view controller is pushed on a navigation controller which is itself contained in a tab bar controller, if any view controller in the navigation stack of the navigation controller has the
hidesBottomBarWhenPushed
property set, then the tab bar should be hidden.So the tab bar is hidden when a navigation controller is selected and one of the view controllers in its stack have the
hidesBottomBarWhenPushed
property set.子类化 UINavigationController 并实现 hidesBottomBarWhenPushed 后面的 setter(或子类化 UIViewController 以直接子类化 hidesBottomBarWhenPushed 方法)并将调用委托给 UITabBar(通过直接调用或 NSNotification)。
Subclass UINavigationController and implement the setter behind hidesBottomBarWhenPushed (or subclass the UIViewController to directly subclass the hidesBottomBarWhenPushed method) and delegate the call to the UITabBar (through a direct call or a NSNotification).