如何知道tabbar是否隐藏在tabbarcontroller推送的controller中?
How to know whether the tab bar is hidden in the controller pushed by a tabbarcontroller?
我想观察tab的状态bar.I需要知道tab栏是否隐藏在controller pushed by a controller on TabBarController.The tab bar在被TabBarController.So如何知道标签栏是否隐藏。
顺便说一句,我曾尝试检查标签栏中的 属性 "isHidden",但它并没有 work.It 总是 NO。
有人知道这个方法吗?请教我。非常感谢!
您可以通过执行以下操作从控制器引用标签栏:
guard let parentTabController = tabBarController as?
MasterViewController else { return }
if parentTabController.tabBar.isHidden{
//Logic if hidden
}else{
//Logic if not hidden
}
MasterViewController 是我正在使用的标签栏的class。希望这对你有帮助,我不确定你是如何引用你的标签栏控制器的,但这应该有效。
如果您有自定义标签栏,您可以通过这种方式引用任何自定义属性。
在这种情况下,我们将需要使用 NotificationCenter,因为在执行 View-Life cycle 方法后您的状态会发生变化。
从您设置 TabBar 隐藏的位置编写此代码
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "TabBarHiddenStatusChanged"), object: nil)
这在 ViewController 的 viewDidLoad() 中,您正在检查其状态
NotificationCenter.default.addObserver(self, selector: #selector(YourViewControllerName.TabBarStatusCheck), name: NSNotification.Name(rawValue: "TabBarHiddenStatusChanged"), object: nil)
添加此方法
func TabBarStatusCheck() {
if(self.tabBarController?.tabBar.isHidden
== true){
}
}
You can use the following line of code to hide the tab bar for particular view controller:-
[self.tabBarController.tabBar setHidden:YES];
With this code you can hide the tab bar for particular view controller while pushing.
You can check the following condition in ViewWillAppear() or ViewDidLoad() method
if (self.tabBarController.hidden)
{
NSLog("Tab Bar Controller Is Hidden");
}
else
{
NSLog("Tab Bar Controller Is Not Hidden");
}
我想观察tab的状态bar.I需要知道tab栏是否隐藏在controller pushed by a controller on TabBarController.The tab bar在被TabBarController.So如何知道标签栏是否隐藏。 顺便说一句,我曾尝试检查标签栏中的 属性 "isHidden",但它并没有 work.It 总是 NO。 有人知道这个方法吗?请教我。非常感谢!
您可以通过执行以下操作从控制器引用标签栏:
guard let parentTabController = tabBarController as?
MasterViewController else { return }
if parentTabController.tabBar.isHidden{
//Logic if hidden
}else{
//Logic if not hidden
}
MasterViewController 是我正在使用的标签栏的class。希望这对你有帮助,我不确定你是如何引用你的标签栏控制器的,但这应该有效。
如果您有自定义标签栏,您可以通过这种方式引用任何自定义属性。
在这种情况下,我们将需要使用 NotificationCenter,因为在执行 View-Life cycle 方法后您的状态会发生变化。
从您设置 TabBar 隐藏的位置编写此代码
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "TabBarHiddenStatusChanged"), object: nil)
这在 ViewController 的 viewDidLoad() 中,您正在检查其状态
NotificationCenter.default.addObserver(self, selector: #selector(YourViewControllerName.TabBarStatusCheck), name: NSNotification.Name(rawValue: "TabBarHiddenStatusChanged"), object: nil)
添加此方法
func TabBarStatusCheck() {
if(self.tabBarController?.tabBar.isHidden
== true){
}
}
You can use the following line of code to hide the tab bar for particular view controller:-
[self.tabBarController.tabBar setHidden:YES];
With this code you can hide the tab bar for particular view controller while pushing.
You can check the following condition in ViewWillAppear() or ViewDidLoad() method
if (self.tabBarController.hidden)
{
NSLog("Tab Bar Controller Is Hidden");
}
else
{
NSLog("Tab Bar Controller Is Not Hidden");
}