我有一个 tableView,其 Storyboard中的约束占据了整个 super View 。在关联 VC 的 viewDidLoad(..) 中,我加载一个 .xib (UIView),然后将其添加为 tableView 的 subview 。
let emptyHomescreenView = EmptyHomescreenView() //The nib is loaded earlier.
self.tableView.addSubview(emptyHomescreenView)
无论如何,我发现emptyHomeScreenView的高度比应有的要长。它正确放置在 tableView 中,但问题只是在于高度。我尝试手动将高度设置为与 tableView 相同,但没有任何变化。我还尝试将 tableView 的 contentInset.bottom 设置为新值,但这也没有改变(奇怪的是 top 确实有效)。
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: -self.navigationController!.toolbar.frame.size.height, right: 0)
//Above line doesn't work, setting a value for top does modify the emptyHomescreenView however.
然后我尝试了
self.edgesForExtendedLayout = UIRectEdge.Bottom
这降低了emptyHomescreenView的高度,但它仍然与navController的底部工具栏不太对齐。
有谁知道为什么会这样吗?我正在为 xib 使用自动布局。
最佳答案
您的 contentInset 正在双重突出您的内容。将 contentInset 的所有值设置为 0。TableView 应该已经与工具栏齐平,并且 tableView 的内容 View 是相对于 tableview 的边界而不是全局 View 空间来测量的。
关于ios - UITableView 的 subview 与 tableView 的高度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36611294/