【问题标题】:TabBar and NavigationBar view partly hiddenTabBar 和 NavigationBar 视图部分隐藏
【发布时间】:2014-01-13 08:50:12
【问题描述】:

希望,第三次幸运:

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

我已经尝试了几乎所有方法,但无济于事。

在 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;
}

我明白了:

如果我在AppDelegate 中添加两行:

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

一切都变得非常混乱:

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

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

self.edgesForExtendedLayout = UIRectEdgeNone;

进入视图控制器,我得到:

半透明条,导航栏下方的红色边框正确位置,但tabBar下方的底部边框。

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

谁能告诉我如何在不使用界面生成器的情况下让内容适合导航栏下方、标签栏上方。

提前致谢。

【问题讨论】:

    标签: ios objective-c ios7 uinavigationcontroller uitabbarcontroller


    【解决方案1】:

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

    当您使用 self.edgesForExtendedLayout = UIRectEdgeNone; 时,请考虑 iOS 7 中的另外三件事

    1. 你有一个NavigationBar
    2. 您有一个Status Bar(时间、网络、电池显示在顶部)
    3. 您也在考虑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];
    

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

    希望对你有帮助。

    【讨论】:

    • 非常感谢您的帮助......但我不禁想知道是否有比这更简单的事情?我原以为使用self.edgesForExtendedLayout 会相应地使视图适合,而无需计算所有单个组件的高度。
    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 2020-02-15
    • 2017-01-12
    • 2019-10-27
    • 2012-01-31
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多