由于我以基于标签的方式启动我的应用程序,现在我想禁用整个标签栏,我该如何实现?这是我在Appdelegate中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3=[[temptable alloc]initWithNibName:@"temptable" bundle:nil];
UIViewController *viewController4=[[about alloc]initWithNibName:@"about" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,viewController4, nil];
self.window.rootViewController=[self tabBarController];
//self.window.rootViewController =viewController2;
[self.window makeKeyAndVisible];
return YES;
}
我只想隐藏整个标签栏,并希望将viewController2
作为带导航控制器的主页。任何人都可以帮忙吗?
答案 0 :(得分:1)
尝试使用我曾经隐藏过的两种方法。显示标签栏
- (void)hideTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
[UIView animateWithDuration:0.5
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds);
tabBar.frame = tabFrame;
//content.frame = window.bounds;
}];
}
- (void)showTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
[UIView animateWithDuration:0.5
animations:^{
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;
}];
}
答案 1 :(得分:0)
如果你想保留UITabBarController实例并只显示你已经添加到UITabBarController全屏的一个视图,那么在UITabBarController上以模态方式显示视图呢?
UINavigationController navController = [[UINavigationController alloc] initWithRootViewController:viewController2];
[self.tabBarController presentModalViewController:navController animated:NO];