iOS开发tabbar的设置及隐藏

本文介绍了在iOS开发中如何自定义TabBar,并在Push操作时实现TabBar的隐藏。通过设置TabBar并将其添加到系统视图上,以及利用setHidesBottomBarWhenPushed方法在导航控制器push时隐藏TabBar。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先在自定义tabbar的时候,将tabbar直接加到系统上面

实现代码:

<strong><span style="font-family:SimHei;font-size:18px;color:#993300;background-color: rgb(255, 255, 255);"> //初始化定义tabbar的背景
    _TabBarBG = [[UIImageView alloc] init];
    _TabBarBG.frame = [self.tabBar bounds];
    _TabBarBG.userInteractionEnabled = YES;
    [_TabBarBG setImage:[UIImage imageNamed:@"tabbarbg"]];
    [self.tabBar addSubview:_TabBarBG];
</span></strong>

在开发中如果在第一个页面中push到下一个页面的,并且想要隐藏tabbar

实现代码:

在push触发之前设置:setHidesBottomBarWhenPushed

<strong><span style="font-family:SimHei;font-size:18px;color:#993300;background-color: rgb(255, 255, 255);">- (void)pushView
{
    [self setHidesBottomBarWhenPushed:YES];
    OtherViewController *other = [[OtherViewController alloc]init];
    [self.navigationController pushViewController:other animated:YES];
}
</span></strong>

之后在同时加入:

<strong><span style="font-family:SimHei;font-size:18px;color:#993300;background-color: rgb(255, 255, 255);">- (void)viewWillDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self setHidesBottomBarWhenPushed:NO];
}
</span></strong>

这样就可以隐藏tabbar,由于我们自定一的tabbar是直接加在系统默认的tabbar上面的。所以这样一来,既能够隐藏自定义的tabbar也可以直接隐藏系统默认的tabbar。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值