有人隐藏/显示标签栏时是否有任何标签栏事件通知? [英] Are there any Tab Bar events for notifying when someone hides/shows the Tab Bar?

查看:149
本文介绍了有人隐藏/显示标签栏时是否有任何标签栏事件通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我创建的Tab Bar控制器的自定义子类中有一个导航控制器。



只要其中一个显示的控制器尝试隐藏或显示标签栏,我就想从(自定义)选项卡栏中知道。 (例如,将具有其hidesBottomBarWhenPushed = YES的VC推送到Nac控制器上)。



总之,我想要收到隐藏/显示标签栏的事件的通知,在苹果的参考中找不到任何东西。我试着看看UITabBar,UITabBarDelegate,UITabBarController和UITabBarControllerDelegate,但似乎只提供与标签栏项相关的功能。



提前感谢

解决方案

如果您使用标签栏控制器,UIKit会明确指出,将在标签栏控制器上下文中显示的每个导航控制器实例将在其 viewControllers 属性。现在每个 UINavigationController 实例有一个委托,它定义了一个 navigationController:willShowViewController:animated:方法,让你知道什么时候视图控制器被推到它上面。



通过将标签栏控制器设置为推送到其上的每个导航控制器的代理,您可以分析被推送的视图控制器有 hidesBottomBarWhenPushed 属性设置,并在这种情况下生成一个事件。



用于隐藏选项卡的算法条控制器的标签栏如下所示:当视图控制器被按在本身包含在标签栏控制器中的导航控制器上时,如果导航控制器的导航堆栈中的任何视图控制器具有 hidesBottomBarWhenPushed 属性集,那么标签栏应该被隐藏。



所以当选择导航控制器时,选项卡栏被隐藏,并且其中一个视图控制器在其堆栈中有 hidesBottomBarWhenPushed 属性集。


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.

解决方案

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 every UINavigationController instance has a delegate, which defines a navigationController: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.

这篇关于有人隐藏/显示标签栏时是否有任何标签栏事件通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆