我有一个tabbarcontroller作为主控制器,当一个视图被推动时我想隐藏它。我使用hidesBottomBarWhenPushed但不工作。感谢。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
答案 0 :(得分:2)
尝试在您的父视图控制器中按下此控制器时添加此行:
YourViewController *controller = [[YourViewController alloc]init....];
controller.hidesBottomBarWhenPushed = YES;
//then push the view controller
祝你好运
答案 1 :(得分:1)
这仅在tabBarController的viewControllers之一是UINavigationController时才有效。仅当视图控制器被推入UINavigationController的堆栈时才会遵守hidesBottomBarWhenPushed
属性,如果它是根视图控制器则不会做太多。
答案 2 :(得分:0)
我已经实现了我自己的自定义tabBarController(它扩展了原来的 UITabBarController ),因为我需要在某些情况下(如设备轮换)以编程方式切换条形图,这是我的实现(评论解释如何它有效):
- (void)hideBottomBar:(BOOL)hide
{
@try
{
// UITabBarController has 2 subviews:
// - the first (index:0) is that one containing the active view controller's view
// - the second (index:1) is that one containing the UITabBar (self.tabBar)
UIView *topView = [self.view.subviews objectAtIndex:0];
UIView *bottomView = [self.view.subviews objectAtIndex:1];
// hide tabs container if necessary
[bottomView setHidden:hide];
// adjust frame
if (hide)
{
// expand main view to fit available space
[topView setFrame:self.view.bounds];
}
else
{
// restore main view frame
CGRect frame = topView.frame;
frame.size.height -= bottomView.frame.size.height;
[topView setFrame:frame];
}
}
@catch (NSException *exception)
{
[[GTMLogger sharedLogger] logError:@"Error occured adjusting tabs view: %@", exception.description];
}
}