Tab Bar涵盖iOS7中的TableView单元格

JuJ*_*oDi 31 objective-c uitabbarcontroller uitableview ios7

我有一个自定义tableViewController,我将其添加到TabBarController中

self.tabBarController.viewControllers = [NSArray arrayWithObjects:someOtherViewController, customTableViewController, nil];
self.tabBarController.selectedIndex = 1;
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,运行iOS7的iPhone 4屏幕底部的标签栏覆盖了最后1.5个tableViewCells.当我使用iOS模拟器 - iPhone Retina(4英寸)/ iOS 7.0时,问题仍然存在.

如何使tableView与屏幕底部的tabBar顶部对齐,而不使用"魔术数字"?

dar*_*iaa 76

试试这个CustomViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIEdgeInsets adjustForTabbarInsets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
    self.scrollView.contentInset = adjustForTabbarInsets;
    self.scrollView.scrollIndicatorInsets = adjustForTabbarInsets;
}
Run Code Online (Sandbox Code Playgroud)

  • 知道了,我不确定这是我想要的修复但是有效 (4认同)

Han*_*One 50

这是一个iOS 8解决方案,但它可以在iOS 7上工作:转到故事板>选择表视图控制器>取消选中"在底栏下".而已!

例

  • 好的功能,它是更优雅的答案......但同时它使tabBar灰色的背景...这不是我想要的. (12认同)
  • 它是灰色的,因为你有tabBar半透明 (3认同)

jar*_*air 7

contentInset使用.bottom值为49的点设置表视图应该更正此问题.

在正确的配置下,YES调用iOS 7上的新UIViewController属性的设置automaticallyAdjustsScrollViewInsets应该纠正这个问题,但(再次)它取决于许多其他因素(视图层次结构,父视图控制器的设置等).


Mat*_*ros 6

接受的答案对我来说并不适用 - 我的设置有点不同.我是以编程方式创建我的视图控制器.我的应用程序的根是一个标签栏控制器,一个选项卡是导航控制器,其根是一个UIViewController以表视图作为主视图.

对我来说有用的是当我手动计算表视图的高度并在alloc-initing table视图时将其设置在框架中.通用公式是:

屏幕高度 - (状态栏高度+导航栏高度+标签栏高度)


sha*_*dox 5

CGFloat bottom =  self.tabBarController.tabBar.frame.size.height;
NSLog(@"%f",bottom);
[self.tableview setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, bottom, 0)];
self.tableview.contentInset = UIEdgeInsetsMake(0, 0, bottom, 0);
Run Code Online (Sandbox Code Playgroud)