【问题标题】:tab bar hide in tab bar based application标签栏隐藏在基于标签栏的应用程序中
【发布时间】:2012-09-12 04:40:58
【问题描述】:

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

【问题讨论】:

  • 你想使用你的自定义标签还是只是想删除标签栏控制器?
  • @saadnib 我想删除标签栏

标签: iphone ios uiviewcontroller uinavigationcontroller


【解决方案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;
                 }];
}

【讨论】:

  • 而不是隐藏如何禁用整个标签栏@Shantanu
【解决方案2】:

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

UINavigationController navController = [[UINavigationController alloc] initWithRootViewController:viewController2];
[self.tabBarController presentModalViewController:navController animated:NO];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-24
    • 2012-02-04
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 2019-03-01
    • 2011-04-14
    • 2011-12-31
    相关资源
    最近更新 更多