UITabbarController使用(二)隐藏和显示tabbar

我们在使用UITabbarController控制器的时候,其底部的菜单一直都是显示的,如果我们push到某个页面的时候,其底部菜单依然存在,这个时候我们就需要将底部菜单给隐藏起来,等返回到各菜单的第一个页面的时候再显示出来;

我使用的方法是消息通知,具体如下:

@property (nonatomic, strong) UITabBarController* mainTabBarController;


1、声明两个消息名:

static NSString* kHidTabbarNotify = @"kHidTabbarNotify";

static NSString* kShowTabbarNotify = @"kShowTabbarNotify";


2、在AppDelegate文件中注册两个消息:

[[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(hidTabbarNotify:)

                                                 name:kHidTabbarNotify

                                               object:nil];

[[NSNotificationCenter defaultCenteraddObserver:self

                                             selector:@selector(showTabbarNotify:)

                                                 name:kShowTabbarNotify

                                               object:nil];


- (void)hidTabbarNotify:(NSNotification*)notify

{

    if (self.mainTabBarController != nil) {

        self.mainTabBarController.tabBar.alpha = 0;

    }

}


- (void)showTabbarNotify:(NSNotification*)notify

{

    if (self.mainTabBarController != nil) {

        self.mainTabBarController.tabBar.alpha = 1;

    }

}


3、在进行push页面操作前发送隐藏tabbar消息:

[[NSNotificationCenter defaultCenter] postNotificationName:kHidTabbarNotify object:nil];


4、在进入第一个页面的时候发送显示tabbar消息:

- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    

    [[NSNotificationCenter defaultCenter] postNotificationName:kShowTabbarNotify object:nil];

}

不过此处添加发送显示的消息会存在多次发送消息问题,但对于软件处理来说问题应该不大,也不会影响软件正常使用。


目前想到的就是通过消息来进行切换显示和隐藏tabbar状态,后期又更好的方法再进行补充!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lock颠颠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值