视图的大小自己调整,代码只是展示一种思路,细节自己把握
//底部标识View
let tipView = JKWorkBottomCell.createView()
self.footerView = tipView
tipView.frame = CGRect.init(x: 0, y: (SCREEN_HEIGHT - kNavBarHeight - 100 + 10), width: SCREEN_WIDTH, height: 100)
tableView.addSubview(tipView)
tableView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
//MARK: 检测contentSize
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let key = keyPath, let value = change?[.newKey] else {
return
}
if key == "contentSize" {
let tableViewH = self.tableView?.m_height ?? 0
let contentH = (value as? CGSize)?.height ?? 0
NSLog("contentSize=\(value)")
if contentH <= tableViewH {
self.footerView?.m_y = (SCREEN_HEIGHT - kNavBarHeight - 100 + 10)
}
else {
self.footerView?.m_y = (contentH - 10)
}
}
}