簡體   English   中英

UITableView 在 TabBar 下

[英]UITableView is under the TabBar

我有一個帶有自定義單元格的自定義UITableView (每個單元格高度為 70 像素)。

我也有一個 49px UITabBar ,但它隱藏了 tableView。

我試圖將這一行添加到 TableView 的awakeFromNib方法中,但沒有奏效:

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

知道我該如何解決這個問題嗎?

謝謝!

我不知道你到底做了什么,但試試這樣:

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

我希望,這會奏效。

我在處理沒有半透明條的導航控制器中的表格視圖時遇到了這個問題。 我執行了類似於以下的設置:

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]
}

然而,我后來發現在層次結構更高的故事板中,有幾個復選框沒有被選中。 具體這兩個:

調整滾動視圖插圖

在不透明條下

檢查這兩個框消除了關心該視圖控制器中的內容插入和布局擴展行為的需要

這在 Swift 3 中對我有用。

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

您應該使用以下代碼配置相應的視圖控制器以刪除邊緣擴展(默認為 UIRectEdgeAll)

edgesForExtendedLayout = []

試試這個

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

嘗試對 tableView 和 TabBar 使用約束,例如:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM