![](/img/trans.png)
[英]Pull up keyboard while scrolling UITableView and scroll along with the tableView
[英]UITableView's footer is not scrolling along with the table when implemented tableView:heightForFooterInSection:
您使用tableView.tableFooterView
設置的頁腳與部分頁腳不同。
每個部分都可以有一個頁腳,其高度由tableView:heightForFooterInSection:
指定,並且 tableView 本身可以有一個頁腳(在所有部分下方)。 這個頁腳是使用tableView.tableFooterView
設置的,您只需通過設置視圖的框架即可更改其高度。
只需將以下代碼添加到管理 tableview 的控制器的 viewDidLoad 中:
override func viewDidLoad() {
super.viewDidLoad()
//...
// Remove extra separators
tableView.tableFooterView = UIView(frame: CGRectZero)
}
對於類似的情況,我使用了 tableFooterView。
final class TableViewWithDynamicFooter: UITableView {
private var isAwaitnigReloading: Bool = false
private var lastCalculatedFooterSize: CGFloat?
private func setupHeaderHeight() {
guard let footer = self.tableFooterView else { return }
let originContentHeight = self.contentSize.height - (lastCalculatedFooterSize ?? 0)
let emptySpaceUnderContent = self.bounds.height - originContentHeight
let minFooterHeight = footer.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
assert(minFooterHeight != 0, "Footer height constraints don't let usage of systemLayoutSizeFitting")
footer.frame.size.height = max(emptySpaceUnderContent, minFooterHeight)
self.contentSize.height = footer.frame.origin.y + footer.frame.height
lastCalculatedFooterSize = footer.frame.size.height
isScrollEnabled = footer.frame.size.height == minFooterHeight
}
override func reloadData() {
isAwaitnigReloading = true
super.reloadData()
}
override func layoutSubviews() {
super.layoutSubviews()
guard isAwaitnigReloading == true else { return } // allow to calculate footer size once, after reload regardless of the number of layoutSubviews calls
setupHeaderHeight()
isAwaitnigReloading = false
}
}
我的實現演示在這里: https : //github.com/ArturRuZ/TableViewWithDynamicFooter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.