0

希望第三次幸运:的TabBar和导航栏视图部分地隐藏

只是试图获取内容出现下面导航栏和上面的标签栏(有没有它,下面会出现两种)。

我已经尝试几乎所有的东西,无济于事。

随着内rootController了下面的代码,我只是想有一个视图(红色边框,以帮助显示,如果它的工作):

-(void)viewWillAppear:(BOOL)animated{ 

    [super viewWillAppear:animated]; 

    UIView *view1 = [[UIView alloc] initWithFrame:self.view.frame]; 
    view1.layer.borderColor = [UIColor redColor].CGColor; 
    view1.layer.borderWidth = 2.0f; 
    [self.view addSubview:view1]; 

} 

和设置为幸福:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    self.window.backgroundColor = [UIColor whiteColor]; 

    TSTFirstViewController *rootController = [[TSTFirstViewController alloc] init]; 
    rootController.title = @"Hello World"; 

    UINavigationController *firstRootController = [[UINavigationController alloc] initWithRootViewController:rootController]; 
    NSArray *viewControllers = @[firstRootController]; 

    UITabBarController *tabBar = [[UITabBarController alloc] init]; 
    tabBar.viewControllers = viewControllers; 
    tabBar.tabBar.barStyle = UIBarStyleBlack; 
    tabBar.tabBar.translucent = NO; 

    [self.window setRootViewController:tabBar]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

我得到:

enter image description here

如果我添加两个行我AppDelegate

firstRootController.navigationBar.translucent = NO; 
firstRootController.navigationBar.barStyle = UIBarStyleBlack; 

这一切都变得非常混乱:

enter image description here

的红色边框下移,底部边框消失的标签栏下方。并出现一个大的空白。

如果我删除了半透明线,并添加:

self.edgesForExtendedLayout = UIRectEdgeNone; 

到视图控制器,我得到:

enter image description here

半透明的酒吧,在正确的位置红色边框导航栏下,但tabBar下方的下边框。

我相信我已经尝试过所有的组合和所有的想法。

任何人都可以请告诉我如何让内容适合在导航栏下面,在标签栏之上而不使用Interface Builder。

在此先感谢。

回答

2

是的,这里是你的解决方案。

当您使用self.edgesForExtendedLayout = UIRectEdgeNone;笑纳iOS中7三个事情

  1. 你有NavigationBar
  2. 您得到了Status Bar(时间,网络,电池显示顶部)
  3. 您正在考虑TabBar以及。

所以你的实现应该从实际视图高度减去导航栏的高度,状态栏的tabbar。

UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-self.navigationController.tabBarController.tabBar.frame.size.height-[UIApplication sharedApplication].statusBarFrame.size.height)]; 
view1.layer.borderColor = [UIColor redColor].CGColor; 
view1.layer.borderWidth = 2.0f; 
[self.view addSubview:view1]; 

这是使用此代码的附加屏幕。

Screen Shot is attached here

我希望帮助。

+0

非常感谢您的帮助......但我不禁想知道是否有比这更容易的东西?我会认为使用'self.edgesForExtendedLayout'可以使视图适合,而不必计算所有单个组件的高度。 – Darren