我需要做這個應用程式。視圖層次結構是這樣的
UIScrollView
-UIView (Main View)
--UIView (Top View Container)
--UITableview
向上滾動主視圖時,如果表格視圖有很多單元格,表格視圖應該轉到頂部,并且一旦到達頂部。用戶應該能夠滾動表格視圖單元格。我能夠實作它,但它不會自然滾動。

附上我的代碼https://github.com/iamshimak/FinchHomeScreenRedesign.git
uj5u.com熱心網友回復:
首先,永遠不要將 tableview 放在滾動視圖中,這是一種不好的做法。您可以只使用表格視圖示題并在表格視圖單元格之前嵌入您想要的任何型別的視圖。
這是我如何處理它的snipeste:
//MARK: ConfigureTableView
private func configureTableView(){
let footerView = UIView()
footerView.frame.size.height = 50
footerView.backgroundColor = .white
self.tableView.tableFooterView = footerView
self.tableView.tableHeaderView = self.headerView
var newFrame = headerView.frame
newFrame.size.width = view.bounds.width
newFrame.size.height = 300
headerView.frame = newFrame
tableView.backgroundView = UIView()
tableView.backgroundView?.addSubview(backgroundTableView)
}
如您所見,我嵌入了一個 UIView 作為頁腳和另一個名為 headerView 的 UIView 作為頁眉
但是如果您堅持在滾動視圖中使用表格視圖,您可以嘗試使用滾動視圖委托并 detech 滾動視圖正在滾動
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let yOffset = scrollView.contentOffset.y
if scrollView == self.scrollView {
if yOffset >= scrollViewContentHeight - screenHeight {
// logic when using scrollview
}
}
if scrollView == self.tableView {
if yOffset <= 0 {
// logic when using tableview scrollView
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/475982.html
標籤:IOS 迅速 合适的视图 uiscrollview
