objective-c - UITabBar 重叠它的 View

标签 objective-c uiview uitabbarcontroller

在我的应用程序中,我使用的是 UITabBarController。这是它在 IB 中的样子:

enter image description here

TabBarController 用作窗口的 rootViewController。

这是我的代码,我用 View 填充 TabBarController:

tabBar = [[UITabBarController alloc]init];

myViewController1 = [[MyViewController1 alloc] initWithNibName:@"View1" bundle:nil];
myViewController2 = [[MyViewController2 alloc] initWithNibName:@"View2" bundle:nil];
myViewController3 = [[MyViewController3 alloc] initWithNibName:@"View3" bundle:nil];

tabBar.viewControllers = [NSArray arrayWithObjects: myViewController1, myViewController2, myViewController3, nil];

[self.view addSubview:tabBar.view];

如果某个 View 显示在 TabBarController 内部,它位于 TabBar 下方(此 View 的高度为红线)- 因此如果我有一些 TableView,我将看不到最后一两行。我怎样才能实现在 TabBarController 内显示 View (如绿色矩形) - 而不是在标签栏下?

我认为它可以自动完成,如果我使用 UITabBarController 显示某些内容,它会显示在里面而不是下面。

最佳答案

自 iOS7 以来,大部分导航项(包括标签栏)都是半透明的。例如,通过这种方法,用户可以看到 UITableView 中的滚动单元格。

有两种方法可以解决您的问题:

选择不在半透明 UI 元素下扩展您的 Controller :

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

但从我的角度来看,更好的方法是使用 AutoLayout 和

设置自动布局

您可以通过编程方式做到这一点:

[view setTranslatesAutoresizingMaskIntoConstraints: NO];
id topGuide = myViewController.topLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (view, topGuide);

[myViewController.view addConstraints:
    [NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-[view]"
    options: 0
    metrics: nil
    views: viewsDictionary]
];

或者用 Storyboard: enter image description here

关于objective-c - UITabBar 重叠它的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24264131/

相关文章:

iphone - Objective-C 中的正式协议(protocol)和非正式协议(protocol)有什么区别?

iPhone - 在触摸位置使用 UIView 动画

iphone - 如何将UIView转换为没有背景的UIImage?

ios - 使用 UIGestureRecogniser 子类化时未调用 Touches Ended

iOS : How to add Underline in UITabBarItem

iOS swift : Image from label in TabBarItem

ios - 如何在以编程方式创建标签栏 Controller 后添加导航界面(Swift)

ios - 检测应用程序是否从推送通知启动/打开,然后将其重定向到特定的 View Controller

iphone - 快速枚举在objective-c中没有给出正确的对象类型?

ios - <hr> 在 UITextView 中分离 [iOS]