我在过去两天遇到这个问题,但可以找到解决方法。有人可以提供帮助。这是我用于TabBar viewControllers的代码片段。
//设置标签栏
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:5];
self.tabBarController = [[UITabBarController alloc] init];
[tabBarController
setDelegate:self];
UINavigationController *navController = nil;
NSArray *vcArray = [self papulateViewControllers];
//用于标签栏的SetViewController
-(NSArray *) papulateViewControllers{
BrowseViewController *browseVC = [[BrowseViewController alloc] initWithNibName:@"BrowseViewController" bundle:nil];
AlbumViewController *albumVC = [[AlbumViewController alloc] initWithNibName:@"AlbumViewController" bundle:nil];
SubmitStep1VC *submitVC = [[SubmitStep1VC alloc] initWithNibName:@"SubmitStep1VC" bundle:nil];
// SubmitStep1VC *submitVC = [[SubmitStep1VC alloc] initWithNibName:@"SubmitStep1_iPhone5.xib" bundle:[NSBundle mainBundle]];
WallViewController *wallVC = [[WallViewController alloc] initWithNibName:@"WallViewController" bundle:nil];
OptionVC *optionVC = [[OptionVC alloc] initWithNibName:@"OptionVC" bundle:nil];
sliderVCRef = [[SliderVC alloc] initWithNibName:@"SliderVC" bundle:nil];
//Navigation Controllers
UINavigationController *browseNavController = [[UINavigationController alloc] initWithRootViewController: browseVC];
[browseNavController setNavigationBarHidden:YES];
UINavigationController *albumNavController = [[UINavigationController alloc] initWithRootViewController: albumVC];
[albumNavController setNavigationBarHidden:YES];
UINavigationController *submitNavController = [[UINavigationController alloc] initWithRootViewController: submitVC];
[submitNavController setNavigationBarHidden:YES];
UINavigationController *wallNavController = [[UINavigationController alloc] initWithRootViewController: wallVC];
[wallNavController setNavigationBarHidden:YES];
UINavigationController *optionNavController = [[UINavigationController alloc] initWithRootViewController: optionVC];
[optionNavController setNavigationBarHidden:YES];
DDMenuController *browseMenuController = [[DDMenuController alloc] initWithRootViewController:browseNavController];
self.menuController = browseMenuController;
self.menuController.leftViewController = sliderVCRef;
DDMenuController *albumMenuController = [[DDMenuController alloc] initWithRootViewController:albumNavController];
albumMenuController.leftViewController = sliderVCRef;
DDMenuController *submitMenuController = [[DDMenuController alloc] initWithRootViewController:submitNavController];
submitMenuController.leftViewController = sliderVCRef;
DDMenuController *wallMenuController = [[DDMenuController alloc] initWithRootViewController:wallNavController];
wallMenuController.leftViewController = sliderVCRef;
DDMenuController *optionMenuController = [[DDMenuController alloc] initWithRootViewController:optionNavController];
optionMenuController.leftViewController = sliderVCRef;
/// Works fine if i uncomment this line and comment next line of code (Passing Viewcontrollers is fine )
// return [NSArray arrayWithObjects:self.menuController, albumVC, submitVC, wallVC, optionVC, nil];
////******* issue in case i use this line (Passing menuController creates issue of Tabbar )
return [NSArray arrayWithObjects:self.menuController, albumMenuController, submitMenuController, wallMenuController, optionMenuController, nil];
////////////
}
当我尝试从任何上面推送到任何一个viewcontroler时TabBarController标签栏没有隐藏。例子
grandPrizeVC.hidesBottomBarWhenPushed = YES;
它一直向我显示标签栏。
如果我试试
appDelegate.tabbarcontroller.tabbar.hidden = YES;
它显示在新VC上的黑色底栏上。
答案 0 :(得分:0)
您的应用正在执行您已实施的内容。您正在将滑动菜单视图控制器作为子视图控制器添加到tabbar控制器,当然,它不会隐藏。隐藏tabbar的一些建议: 1.将tabbar controller添加为模式到DDMenuController 2.写一些隐藏/显示标签栏的方法(搜索隐藏标签栏会给你答案,或者你可以只遍历标签栏控制器的视图查找标签栏的子视图并隐藏它)。 祝你好运!
答案 1 :(得分:0)
以下为我工作:
显示标签栏:
+ (void) showTabBar{
MyAppDelegate* appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication]delegate];
UITabBar *tabBar = appDelegate.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
tabBar.frame = tabFrame;
CGRect contentFrame = content.frame;
contentFrame.size.height -= tabFrame.size.height;
}
隐藏TabBar:
+(void) hideTabBar{
MyAppDelegate* appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication]delegate];
UITabBar *tabBar = appDelegate.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
[UIView animateWithDuration:0.01
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds);
tabFrame.origin.y +=20;
tabBar.frame = tabFrame;
content.frame = window.bounds;
}];
}