我正在开发一个 iOS 应用程序,它有一个用于显示 TabBar 的 UITabBarController。 在某些地方,我展示了一个隐藏 tabBar 的 modalView 全屏。
我想检测我的 tabBar 何时对用户可见。 有什么方法可以自动检查 de tabBar 是否可见?
我试过了:
但它真的不起作用,因为 tabBar 并没有真正隐藏。
if ([[[appdelegate tabBarController] tabBar] isHidden])
{
NSLog(@"tabBar IS HIDDEN");
}
else
{
NSLog(@"tabBar IS VISIBLE");
}
我在 BaseViewController 中编写这段代码,它是我的模态视图和我项目的其他 View 的父类(super class)。
谢谢。
最佳答案
检查此 [[[self tabBarController] tabBar] isHidden]
没问题,但在一种情况下会失败。如果您在该 View 中(根本)没有标签栏,则 [self tabBarController]
返回 nil
因此调用 isHidden 将返回 NO,这是事实,但您必须检测那是另一种情况。它不是隐藏的,但它不会退出,除了检查你应该添加 [self tabBarController] != nil
。所以基本上:
if([self tabBarController] && ![[[self tabBarController] tabBar] isHidden]){
//is visible
} else {
//is not visible or do not exists so is not visible
}
关于iphone - 检查 tabBar 在 iOS 应用程序上是否可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206838/