代码之家  ›  专栏  ›  技术社区  ›  Jonah

当按下按钮允许全屏查看内容时,是否可以隐藏选项卡?

  •  19
  • Jonah  · 技术社区  · 16 年前

    我在我的基于导航的应用程序的详细视图中有一个UItaBar。我在TableView中存储文本和图像,希望用户能够点击单元格以隐藏导航控制器和用于全屏查看内容的选项卡。

    我找到了隐藏顶栏的代码,但是隐藏顶栏似乎并不容易。

    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
     [self.navigationController setNavigationBarHidden:YES animated:YES];
    

    有人知道怎么做吗?

    加载视图后,此代码无法隐藏选项卡。

      yourTabViewController.hidesBottomBarWhenPushed = YES;
    

    这是我找到的代码。不过,似乎只有在加载视图时才有效,因此一旦显示了选项卡,就不能使用它来隐藏它。我仍在努力工作。请帮忙!!!

        self.tabBarController.tabBar.hidden = YES;
    
    6 回复  |  直到 12 年前
        1
  •  26
  •   Joseph Lin    14 年前

    有一种内置的方法可以做到这一点:

    self.hidesBottomBarWhenPushed = YES;

    但在视图被推送之前,您必须这样做。以下是您可能希望使用的方式:

    ChildViewController* childVC = [[ChildViewController alloc] init];
    childVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:childVC animated:YES];
    [childVC release];
    
        2
  •  8
  •   Jonah    15 年前

    我发现的最佳解决方法是更改视图大小,使其覆盖选项卡。以下是选择行时隐藏状态栏、导航栏和选项卡栏的代码:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (appDelegate.navigationController.navigationBar.hidden == NO)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
        [appDelegate.navigationController setNavigationBarHidden:YES animated:YES];
    
        [UIView beginAnimations:@"HideTabbar" context:nil];
        [UIView setAnimationDuration:.2];
        self.view.frame = CGRectMake(0,0,320,480);
        [UIView commitAnimations];
    }
    if (appDelegate.navigationController.navigationBar.hidden == YES)
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
        [appDelegate.navigationController setNavigationBarHidden:NO animated:YES];
    
        [UIView beginAnimations:@"ShowTabbar" context:nil];
        [UIView setAnimationDuration:.2];
        self.view.frame = CGRectMake(0,0,320,368);
        [UIView commitAnimations];
    }   
    }
    
        3
  •  6
  •   Alex Terente    13 年前

    我的解决方案:

    // Hide tab bar animated
    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionFade];
    [[self.view.window layer] addAnimation:animation forKey:@"layerAnimation"]; 
    [self.tabBarController.tabBar setHidden:YES];
    
    // Display tab bar animated
    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionFade];
    [[self.view.window layer] addAnimation:animation forKey:@"layerAnimation"]; 
    [self.tabBarController.tabBar setHidden:NO];
    

    你必须增加 #import <QuartzCore/QuartzCore.h>

        4
  •  3
  •   David H.    13 年前

    我找到了这个问题的一个答案,非常简单有效。

    解决方案是设置选项 “按下时隐藏下栏” 在所有视图中,查看应用程序的控制器和选项卡栏控制器。

    您可以在ib中或者通过代码来实现这一点。

    希望这能帮助大家…

        5
  •  0
  •   Chase Williams    15 年前

    为了调整窗口的大小,首先需要在Inspector窗口的“属性”选项卡下的状态栏字段中选择“无”选项。然后,Interface Builder将允许您更改窗口的大小。

        6
  •  0
  •   Uri Maimon - Nominal    12 年前

    以防任何人需要单触式操作系统这个很酷的小把戏。(谢谢!)

        // Method implementations
        static void hideTabBar (UITabBarController tabbarcontroller)
        {
            UIView.Animate(0.4, delegate() { 
                foreach(UIView view in tabbarcontroller.View.Subviews)
                {
                    if(view.GetType()==typeof(UITabBar))
                        view.Frame=new  RectangleF(view.Frame.X, 480, view.Frame.Size.Width, view.Frame.Size.Height);
                    else 
                        view.Frame=new  RectangleF(view.Frame.X, view.Frame.Y, view.Frame.Size.Width, 480);
                }
            });
        }
    
        static void showTabBar (UITabBarController tabbarcontroller)
        {
            UIView.Animate(0.4, delegate() { 
                foreach(UIView view in tabbarcontroller.View.Subviews)
                {
                    if(view.GetType()==typeof(UITabBar))
                        view.Frame=new  RectangleF(view.Frame.X, 367, view.Frame.Size.Width, view.Frame.Size.Height);
                    else 
                        view.Frame=new  RectangleF(view.Frame.X, view.Frame.Y, view.Frame.Size.Width, 367);
                }
            });
        }
    
    推荐文章