TabBar和导航栏视图部分隐藏

时间:2014-01-13 08:50:12

标签: ios objective-c ios7 uinavigationcontroller uitabbarcontroller

希望,第三次幸运:

只需尝试将内容显示在导航栏下方和标签栏上方(没有任何内容,也会显示在下方)。

我已经尝试了很多东西,但没有用。

使用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的情况下,在Tab栏上方的导航栏下方放置内容。

提前致谢。

1 个答案:

答案 0 :(得分:2)

是的,这是您的解决方案。

当您使用self.edgesForExtendedLayout = UIRectEdgeNone;时,请考虑在iOS 7中再做三件事

  1. 你有NavigationBar
  2. 你有一个Status Bar(时间,网络,电池显示在上面)
  3. 您正在考虑TabBar
  4. 所以你的实现应该减去导航栏的高度,状态栏&实际视图高度的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

    我希望有所帮助。

相关问题