谁能告诉我如何实现一个有弹性的 UITableView 页脚。
我希望我的页脚中的图像在用户“过度滚动”时拉伸/增加大小。(如果用户在 UITableView 已经在底部时向下滚动)
当前代码:
private let tableFooterHeight: CGFloat = 300
private var footerCustomView = UIImageView()
func setupFooterView(){
// Footer view
self.footerCustomView = UIImageView(frame: CGRect.zero)
self.footerCustomView.backgroundColor = UIColor.brown
self.footerCustomView.image = UIImage(named: "image")
self.view.addSubview(self.footerCustomView)
// self.view.bringSubview(toFront: self.tableView)
self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: self.tableFooterHeight, right: 0)
self.footerCustomView.translatesAutoresizingMaskIntoConstraints = false
let leadingConstraint = NSLayoutConstraint(item: self.footerCustomView,
attribute: .leading,
relatedBy: .equal,
toItem: self.tableView,
attribute: .leading,
multiplier: 1,
constant: 0)
let trailingConstraint = NSLayoutConstraint(item: self.footerCustomView,
attribute: .trailing,
relatedBy: .equal,
toItem: self.tableView,
attribute: .trailing,
multiplier: 1,
constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.footerCustomView,
attribute: .bottom,
relatedBy: .equal,
toItem: self.tableView,
attribute: .bottom,
multiplier: 1,
constant: 0)
let heightConstraint = NSLayoutConstraint(item: self.footerCustomView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height,
multiplier: 1,
constant: self.tableFooterHeight)
self.view.addConstraints([bottomConstraint, trailingConstraint, heightConstraint, leadingConstraint])
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.updateFooterView()
}
func updateFooterView() {
if self.tableView.bounds.origin.y > 1559 { // 1559 is end of tableView
let diff = self.tableView.contentOffset.y - 1559
self.footerCustomView.frame.size.height = self.tableFooterHeight + diff
}
}
谢谢!