简体   繁体   English

UITableView 在 TabBar 下

[英]UITableView is under the TabBar

I have a custom UITableView with custom cells (70px height for each cell).我有一个带有自定义单元格的自定义UITableView (每个单元格高度为 70 像素)。

I have also a 49px UITabBar , but it's hides the tableView.我也有一个 49px UITabBar ,但它隐藏了 tableView。

I've tried to add this line to the TableView awakeFromNib method but it didn't work:我试图将这一行添加到 TableView 的awakeFromNib方法中,但没有奏效:

self.commentsTableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0)

Any idea how can I solve this?知道我该如何解决这个问题吗?

Thanks!谢谢!

i don't know what you did exactly, but try like this:我不知道你到底做了什么,但试试这样:

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);

I hope, this will work.我希望,这会奏效。

I ran into this issue when dealing with a table view in a navigation controller that did not have translucent bars.我在处理没有半透明条的导航控制器中的表格视图时遇到了这个问题。 I performed a setup similar to the following:我执行了类似于以下的设置:

override func viewDidLoad() {
    super.viewDidLoad()

    // Without this there is some extra fast inertia when slowly
    // scrolling to the top.
    extendedLayoutIncludesOpaqueBars = true

    // Don't extend the tableview past the bottom bar, though.
    // If we do then a tab bar or bottom nav bar will block
    // content.
    edgesForExtendedLayout = [.top, .left, .right]
}

However, I later discovered that a couple of checkboxes were unchecked in a storyboard higher up the hierarchy.然而,我后来发现在层次结构更高的故事板中,有几个复选框没有被选中。 Specifically these two:具体这两个:

调整滚动视图插图

在不透明条下

Checking these two boxes removed the need to care about the content insets and the layout extending behavior in that view controller检查这两个框消除了关心该视图控制器中的内容插入和布局扩展行为的需要

This did the trick for me in Swift 3.这在 Swift 3 中对我有用。

if let tabBarController = tabBarController {
    self.tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, tabBarController.tabBar.frame.height, 0.0);
}

您应该使用以下代码配置相应的视图控制器以删除边缘扩展(默认为 UIRectEdgeAll)

edgesForExtendedLayout = []

Try this试试这个

self.commentsTableView.contentInset = UIEdgeInsetsMake(49, 0, 0, 0)
self.commentsTableView.setContentOffset(CGPoint.init(x: 0, y: -49), animated: false)

如果您在之前的视图控制器中更改了self.hidesBottomBarWhenPushed=true ,那么请确保在override func prepare(for segue: UIStoryboardSegue, sender: Any?) {} self.hidesBottomBarWhenPushed=false其更改为self.hidesBottomBarWhenPushed=false

Try to use constraints for tableView and TabBar like:尝试对 tableView 和 TabBar 使用约束,例如:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM