我目前正在使用UITableViewController。我目前的實現包括一個標題視圖(白色視圖),一個UITableView部分標題(紅色視圖)和tableview(灰色)。當前TableView樣式被分組,所以當滾動縮小標題視圖時,Section Header與TableView一起滾動。當頭部位於視圖頂部時取消組合UITableView部分頭部
我試圖保持部分標題在視圖的頂部,當標題視圖離屏時,並允許UITableViewCells在部分標題下滾動。目前,當Section Header到達視圖頂部時,tableview不能向上滾動。任何建議將是超級有用
目前代碼:
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 106.0
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view1 = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 106.0))
view1.backgroundColor = UIColor.red
return view1
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80.0
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let maxOffset = (scrollView.contentSize.height - scrollView.frame.size.height)
if scrollView.contentOffset.y >= maxOffset {
scrollView.contentOffset = CGPoint(x: scrollView.contentOffset.x, y: maxOffset)
}
if scrollView.contentOffset.y >= 35.0 {
scrollView.contentOffset = CGPoint(x: scrollView.contentOffset.x, y: 35.0)
}
}
}
你爲什麼不使用['plain'](https://developer.apple。com/reference/uikit/uitableviewstyle/1614968-plain)table view改爲?標題不會浮動在分組表格視圖中。 – ozgur
要實現這個功能,你應該使用UIViewController。你可以在UIViewController中輕鬆實現這一點,爲什麼使用UITableViewController複雜化。 – Priyansh
當它在視圖中間時,普通表格視圖不會滾動SectionHeader。它仍然在同一個地方 –