iOS如何隐藏各种bar
状态条StatusBar
1 [UIApplication sharedApplication].statusBarHidden = YES;
导航条NavigationBar
1 [self.navigationController setNavigationBarHidden:YES];
TabBar
方法1
1 [self.tabBarController.tabBar setHidden:YES];
这个方法有问题,虽然tabBar被隐藏了,但是那片区域变成了一片空白,无法被其他视图使用。
方法2
对于navigationController+tabBarController的结构,可以在push下一级的childController之前将childController的hidesBottomBarWhenPushed属性设为YES。
比如,可以在childController的初始化方法中做这件事,代码如下:
1 // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
2
3 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
4 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
5 if (self) {
6 // Custom initialization.
7 self.hidesBottomBarWhenPushed = YES;
8 }
9 return self;
10 }
方法3
http://www.azumi.cc/thread-539502-1-1.html
1 - (void)makeTabBarHidden:(BOOL)hide
2 {
3 if ( [self.tabBarController.view.subviews count] < 2 )
4 {
5 return;
6 }
7 UIView *contentView;
8
9 if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
10 {
11 contentView = [self.tabBarController.view.subviews objectAtIndex:1];
12 }
13 else
14 {
15 contentView = [self.tabBarController.view.subviews objectAtIndex:0];
16 }
17 // [UIView beginAnimations:@"TabbarHide" context:nil];
18 if ( hide )
19 {
20 contentView.frame = self.tabBarController.view.bounds;
21 }
22 else
23 {
24 contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
25 self.tabBarController.view.bounds.origin.y,
26 self.tabBarController.view.bounds.size.width,
27 self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
28 }
29
30 self.tabBarController.tabBar.hidden = hide;
31 // [UIView commitAnimations];
32 }
时机
1 - (void)viewWillAppear:(BOOL)animated {
2 [self setFullScreen:YES];
3 }
4
5 - (void)viewWillDisappear:(BOOL)animated {
6 [self setFullScreen:NO];
7 }
8
9 - (void)setFullScreen:(BOOL)fullScreen {
10 // 状态条
11 [UIApplication sharedApplication].statusBarHidden = fullScreen;
12 // 导航条
13 [self.navigationController setNavigationBarHidden:fullScreen];
14 // tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现。
15 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述