关于显示和隐藏TabBar的方法,自己开始不是很懂,查找了很多的资料,在http://blog.csdn.net/riveram/article/details/7345577
这里面,有这样的描述,里面是给了两个方法:
隐藏tabbar的方法:
1 2 3 4 5 6 7 8 9 10 11 12 13
| - (void)hideTabBar { if (self.tabBarController.tabBar.hidden == YES) { return; } UIView *contentView; if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) contentView = [self.tabBarController.view.subviews objectAtIndex:1]; else contentView = [self.tabBarController.view.subviews objectAtIndex:0]; contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height); self.tabBarController.tabBar.hidden = YES; }
|
显示tabbar的方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| - (void)showTabBar
{ if (self.tabBarController.tabBar.hidden == NO) { return; } UIView *contentView; if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) contentView = [self.tabBarController.view.subviews objectAtIndex:1];
else contentView = [self.tabBarController.view.subviews objectAtIndex:0]; contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height); self.tabBarController.tabBar.hidden = NO; }
|
然后直接调用就好了。
另外在cocoachina的网站上,也看到了一个方法,不过只是说是隐藏的方法。
代码如下:
隐藏Tabbar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| - (void)makeTabBarHidden:(BOOL)hide { if ( [self.tabBarController.view.subviews count] < 2 ) { return; } UIView *contentView; if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) { contentView = [self.tabBarController.view.subviews objectAtIndex:1]; } else { contentView = [self.tabBarController.view.subviews objectAtIndex:0]; } if ( hide ) { contentView.frame = self.tabBarController.view.bounds; } else { contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x, self.tabBarController.view.bounds.origin.y, self.tabBarController.view.bounds.size.width, self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height); } self.tabBarController.tabBar.hidden = hide; }
|
但是,有经过资料的查找,有个比较简单的方法
我在A视图的代码可参考如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| -(void) viewWillAppear:(BOOL)animated { self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; _rightButton.titleLabel.font = [UIFont fontWithName:@"Avenir-Book" size:14.0]; _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; _rightButton.contentEdgeInsets = UIEdgeInsetsMake(0.0, 2.0, 0.0, 0.0); [_rightButton setFrame:CGRectMake(0.0, 0.0, 60.0, 30.0)]; NSString *arrowPath = [[NSBundle mainBundle] pathForResource:@"littleArrow" ofType:@"png"];
[_rightButton setBackgroundImage:[UIImage imageWithContentsOfFile:arrowPath] forState:UIControlStateNormal]; [_rightButton addTarget:self action:@selector(personRoleSelect:) forControlEvents:UIControlEventTouchUpInside]; if([_role isEqualToString:@""] || (_role == nil)) { [_rightButton setTitle:@"全部" forState:UIControlStateNormal]; } else { [_rightButton setTitle:[NSString stringWithFormat:@"%@",_role] forState:UIControlStateNormal]; } [_rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; UIBarButtonItem *rightItemBar = [[UIBarButtonItem alloc] initWithCustomView:_rightButton]; self.navigationItem.rightBarButtonItem = rightItemBar; self.hidesBottomBarWhenPushed = YES; UIBarButtonItem *returnItem = [[UIBarButtonItem alloc] init]; returnItem.title = @"返回"; self.navigationItem.backBarButtonItem = returnItem; }
-(void) viewWillDisappear:(BOOL)animated { self.hidesBottomBarWhenPushed = NO; [_dropDown hideDropDown:_rightButton]; }
|
主要是这句:
self.hidesBottomBarWhenPushed = YES;
和
self.hidesBottomBarWhenPushed = NO;