iOS 各种bar的隐藏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CrazyDuang/article/details/49794341

ios 各种bar的隐藏   

iOS 隐藏各种bar  

状态条StatusBar
[UIApplication sharedApplication].statusBarHidden = YES;

导航条NavigationBar
[self.navigationController setNavigationBarHidden:YES];

TabBar

方法1
[self.tabBarController.tabBar setHidden:YES];
这个方法有问题,虽然tabBar被隐藏了,但是那片区域变成了一片空白,无法被其他视图使用。

方法2
对于navigationController+tabBarController的结构,可以在push下一级的childController之前将childController的hidesBottomBarWhenPushed属性设为YES。
比如,可以在childController的初始化方法中做这件事,代码如下:
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 }

- (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 }





猜你喜欢

转载自blog.csdn.net/CrazyDuang/article/details/49794341
今日推荐