1

由于我使用基于选项卡的应用程序启动我的应用程序,现在我想禁用整个选项卡栏,我该如何实现?这是我在 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使用导航控制器作为主页。有人可以帮忙吗?

4

2 回答 2

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;
                 }];
}
于 2012-09-12T04:47:06.787 回答
0

如果您想保留 UITabBarController 实例并仅全屏显示您添加到 UITabBarController 的视图之一,那么以模态方式在 UITabBarController 上显示视图怎么样?

UINavigationController navController = [[UINavigationController alloc] initWithRootViewController:viewController2];
[self.tabBarController presentModalViewController:navController animated:NO];
于 2012-09-12T04:54:28.457 回答