我有一个带有一堆自定义单元格的 UITableView
(每个单元格都有自定义高度和动态高度)。
我想向 tableview 添加一个页脚 View ,它始终位于 tableView contentSize 的底部。
如果 contentSize 大于屏幕尺寸,那么在 tableView 的底部(向下滚动,就像常规的最后一个单元格一样)。
如果 contentSize 小于屏幕尺寸,那么页脚仍将位于屏幕底部,并且从最后一个单元格到页脚会有一个间隙。
我试过像这样添加页脚:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let myFooterView = Bundle.main.loadNibNamed("MyFooterView", owner: self, options: nil)?.first as! MyFooterView
myFooterView.delegate = self
myFooterView.frame = CGRect(x: 0, y: 0, width: self.tableView.frame.size.width, height: 100)
return myFooterView
}
但是当我滚动时,页脚漂浮在底部。这不是我想要实现的目标。
知道如何实现我想要的非 float 页脚吗?
谢谢! :)
最佳答案
在 TableView 中添加一个 View 作为 subview ,并在scrollView:didScroll:
中调整位置。为了能够做到这一点,请将对 UIScrollViewDelegate
的一致性添加到您的 View Controller 。我认为 UITabelViewController
自动成为 TableView 的委托(delegate)(这也是一个 UIScrollView
)。
棘手的部分是根据内容大小、内容偏移量、 View 大小和页脚大小计算位置。
关于ios - 非 float UITableView 页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46174494/