在我的应用程序中,我使用的是 UITabBarController。这是它在 IB 中的样子:
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:
关于objective-c - UITabBar 重叠它的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24264131/