ios TableView 显示在标签栏后面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20884381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:57:07  来源:igfitidea点击:

TableView Showing Behind Tab Bar

iosobjective-cuitableviewios7uitabbar

提问by raginggoat

I am updating my app to use iOS 7 and I'm having a problem with a table view. My tab bar is translucent. The problem is when I scroll to the bottom of my table view, part of the last cell is still behind the tab bar. I'd like to have a bit of space between the last cell and the tab bar. I could fix this by using an opaque tab bar instead, but I want to keep it translucent.

我正在更新我的应用程序以使用 iOS 7,但我在使用表格视图时遇到了问题。我的标签栏是半透明的。问题是当我滚动到表格视图的底部时,最后一个单元格的一部分仍然在标签栏后面。我想在最后一个单元格和标签栏之间留一点空间。我可以通过使用不透明的标签栏来解决这个问题,但我想让它保持半透明。

enter image description here

在此处输入图片说明

回答by Johnykutty

Try setting

尝试设置

self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;

Inside the tableview controller

在 tableview 控制器内部

回答by Hemang

Swift 4.x

斯威夫特 4.x

let adjustForTabbarInsets: UIEdgeInsets = UIEdgeInsetsMake(0, 0, self.tabBarController!.tabBar.frame.height, 0)
self.yourTableView.contentInset = adjustForTabbarInsets
self.yourTableView.scrollIndicatorInsets = adjustForTabbarInsets

回答by CoolMonster

Check the screen shot

检查屏幕截图

enter image description here

在此处输入图片说明

Check the under top Bar and Un-checke under Bottom Bar

检查下顶部栏和取消底部栏下的检查

回答by mehdok

SWIFT 3

斯威夫特 3

put this inside viewDidLoadof your tableViewController:

把它放在viewDidLoad你的里面tableViewController

self.edgesForExtendedLayout = UIRectEdge()
self.extendedLayoutIncludesOpaqueBars = false
self.automaticallyAdjustsScrollViewInsets = false

回答by kemicofa ghost

Swift 3.0

斯威夫特 3.0

This is what worked for me. In your Custom ViewController:

这对我有用。在您的自定义 ViewController 中:

override func viewDidLoad() {
    super.viewDidLoad()

    let adjustForTabbarInsets: UIEdgeInsets = UIEdgeInsetsMake(self.tabBarController!.tabBar.frame.height, 0, 0, 0);
    //Where tableview is the IBOutlet for your storyboard tableview.
    self.tableView.contentInset = adjustForTabbarInsets;
    self.tableView.scrollIndicatorInsets = adjustForTabbarInsets;
}

回答by Manu

Not to sure I like the solution but it works for me.

不确定我喜欢这个解决方案,但它对我有用。

With iOS 11 I have no issue, I simply use the following in viewDidLoad():

使用 iOS 11 我没有问题,我只是在以下内容中使用viewDidLoad()

self.collectionView.bottomAnchor.constraint(self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true

However on iOS 10 I need to hack my way like this:

但是在 iOS 10 上,我需要像这样破解我的方法:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let tabBarHeight: CGFloat = (self.parent?.tabBarController?.tabBar.frame.size.height)!

    if #available(iOS 11.0, *) {

    } else {
        self.collectionView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -tabBarHeight).isActive = true
    }
 }

回答by Sreeraj VR

This is working for me

这对我有用

override func viewDidLoad() { self.edgesForExtendedLayout = UIRectEdge() self.extendedLayoutIncludesOpaqueBars = false }

override func viewDidLoad() { self.edgesForExtendedLayout = UIRectEdge() self.extendedLayoutIncludesOpaqueBars = false }

回答by David.Chu.ca

It is really hard to resolve the issue without detail information or actual codes. I have similar issue of tabview behind UItabBar in my project. The solutions offered here do not work in my case. After exploring my codes, I found a solution for my case.

如果没有详细信息或实际代码,很难解决问题。我的项目中 UItabBar 后面有类似的 tabview 问题。这里提供的解决方案在我的情况下不起作用。在探索了我的代码之后,我找到了适合我的案例的解决方案。

Here is brief explanation of my case. I have a UItabBar in main view with two tab buttons. In one tab view, there is table view. If user taps on a row, a detail view is presented by using navigation controller. In the detail view, the tab bar is hidden, and a toolbar is showing at the bottom.

这是我的案例的简要说明。我在主视图中有一个带有两个选项卡按钮的 UItabBar。在一个选项卡视图中,有表格视图。如果用户点击一行,则使用导航控制器显示详细信息视图。在详细视图中,标签栏被隐藏,工具栏显示在底部。

In order to bring tab bar back and hide the toolbar when the main view is brought back, I have to explicitly show tab bar and hide toolbar in the event of viewWillAppear:

为了在主视图被带回时带回标签栏并隐藏工具栏,我必须在 viewWillAppear 事件中显式显示标签栏和隐藏工具栏:

class myMainViewController: UITableViewController {
  private var tabBarHidden: Bool? = {
    didSet {
      self.tabBarController?.tabBar.isHidden = tabBarIsHidden ?? true
    }
  }

  private var toolBarIsHidden: Bool? {
    didSet {
      let hidden = toolBarIsHidden ?? true
        self.navigationController?.toolbar.isHidden = hidden
        self.navigationController?.setToolbarHidden(hidden, animated: true)
      }
  }
  ...
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBarIsHidden = false
    self.toolBarIsHidden = true
  }
  ...
}

I finally realize that the visibility of bar at the bottom is set in the event of viewWillAppear. At that time, the tableView or scroll view's content insets are set already based on no bar at the bottom. That's why my tableView is behind the bottom bar.

我终于意识到底部栏的可见性是在 viewWillAppear 事件中设置的。那时,tableView 或滚动视图的内容插入已经基于底部没有栏设置。这就是为什么我的 tableView 在底部栏后面。

The solution I found is to reset content insets in the event of viewDidAppear:

我找到的解决方案是在 viewDidAppear 事件中重置内容插入:

override func viewDidAppear(_ animated: Bool) {
  // In the event of viewWillAppear, visibilities of tool bar and tab bar are set or changed,
  // The following codes resets scroll view's content insets for tableview
  let topInset = self.navigationController!.navigationBar.frame.origin.y +
    self.navigationController!.navigationBar.frame.height
  let adjustForTabbarInsets: UIEdgeInsets = UIEdgeInsetsMake(
        topInset, 0,
        self.tabBarController!.tabBar.frame.height, 0)
  self.tableView.contentInset = adjustForTabbarInsets
  self.tableView.scrollIndicatorInsets = adjustForTabbarInsets
}

回答by Spentak

If any view shows behind a UITabBar you can grab the bottomLayoutGuide and make adjustments at runtime. What I do is have a BaseViewController that all my view controllers inherit from. Then if the tab bar is visible we adjust the view like so:

如果任何视图显示在 UITabBar 后面,您可以获取 bottomLayoutGuide 并在运行时进行调整。我所做的是有一个 BaseViewController,我的所有视图控制器都继承自它。然后,如果标签栏可见,我们像这样调整视图:

import UIKit

class BaseVC: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
}

override func viewDidLayoutSubviews() {
    //Ensures that views are not underneath the tab bar
    if tabBarController?.tabBar.hidden == false {
        var viewBounds = self.view.bounds;
        var bottomBarOffset = self.bottomLayoutGuide.length;
        self.view.frame = CGRectMake(0, 0, viewBounds.width, viewBounds.height - bottomBarOffset)
    }
  }
}

Since I don't use storyboards (where you can click a checkbox in IB to fix this problem), this has been the best solution I have found.

由于我不使用故事板(您可以单击 IB 中的复选框来解决此问题),因此这是我找到的最佳解决方案。

回答by PunjabiCoder

You need to adjust the height of the table view. Just leave 49px at the bottom, as the tabbar height is 49 px. Adjust the height of table view so that it leaves 49px space below it.

您需要调整表格视图的高度。只需在底部留下 49 像素,因为标签栏高度为 49 像素。调整 table view 的高度,使其下方留出 49px 的空间。