ios - 非 float UITableView 页脚

标签 ios iphone swift uitableview cocoa-touch

我有一个带有一堆自定义单元格的 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/

相关文章:

ios - 按下导航 Controller 左栏按钮时如何停止 View 消失

ios - 在 TableView 的单元格中创建 TableView

iOS 火猴 : How to send email from iOS App though mail app in Firemonkey Delphi XE7

ios - 在 pageViewController 内的 tableView 上滑动以删除

iphone - 背景大小 : cover looks pixelated on retina display

iphone - 像IOS一样集成Twitter - 5

ios - 无法访问单元格 subview Swift

ios - UIImage 在 self 调整 UITableViewCell 拉伸(stretch)

iphone - 如何在负位置的 subview 上点击

ios - iPhone 从键中的值获取数组的索引