检查tabBar是否在iOS应用上可见 [英] Check if tabBar is visible on iOS app

查看:104
本文介绍了检查tabBar是否在iOS应用上可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序,它有一个用于显示TabBar的UITabBarController。
在某些地方,我提供了一个隐藏tabBar的modalView全屏。

I am working on an iOS App that have an UITabBarController for show a TabBar. In some where, I present a modalView full screen that hides the tabBar.

我想检测我的tabBar何时对用户可见。
如果de tabBar可见,有没有办法自动检查

I want to detect when my tabBar is visible for the user. There is any way to check automatically when de tabBar is visible or not?

我试过了:

但它真的不起作用,因为tabBar并没有真正隐藏。

But it really don't work because the tabBar is not really hidden.

if ([[[appdelegate tabBarController] tabBar] isHidden])
{
    NSLog(@"tabBar IS HIDDEN");
}
else
{
    NSLog(@"tabBar IS VISIBLE");
}

我在BaseViewController中编写此代码,这是我的模态视图的超类我项目的其他观点。

I write this code in a BaseViewController which is super class of my modal view and the other views of my project.

谢谢。

推荐答案

检查这个 [[[tabBarController] tabBar] isHidden] 很好,但在一种情况下会失败。如果你在该视图中没有标签栏(根本),那么 [self tabBarController] 返回 nil 所以调用isHidden将返回NO,这是真理,但你必须检测到这种情况,这是其他情况。它没有被隐藏但它不会退出,除了检查你应该添加 [self tabBarController]!= nil 。所以基本上:

Checking this [[[self tabBarController] tabBar] isHidden] is fine but in one case it will fail. If you do not have tab bar in that view (at all) then [self tabBarController] returns nil so calling isHidden will return NO which is the truth but you have to detect that situation that it is other case. It is not hidden but it doesn't exits so, except that checking you should add [self tabBarController] != nil. So basically:

if([self tabBarController] && ![[[self tabBarController] tabBar] isHidden]){
    //is visible
} else {
    //is not visible or do not exists so is not visible
}

这篇关于检查tabBar是否在iOS应用上可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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