【问题标题】:Scrolling whole screen and not just tableview滚动整个屏幕而不仅仅是 tableview
【发布时间】:2018-01-08 03:40:29
【问题描述】:

抱歉,这是一个基本问题。我有一个从屏幕中间开始的带有 Tableview 的 UIViewController。我可以让我的 tableview 滚动,但我希望能够滚动整个屏幕,而不仅仅是从 tableview 开始。现在,当我滚动时,屏幕的上半部分保持固定,只有 tableview 滚动,但我想开始滚动整个屏幕。

【问题讨论】:

  • 嘿 - 我需要澄清你的问题。你的表格视图会滚动吗?您是否希望它被滚动锁定并且只有屏幕能够滚动?如果您澄清这些细节,我可以帮助您!
  • 无论你想从 tableView 滚动什么,都将这些内容放在 tableViewHeader 或 tableViewFooter 中。
  • @cloudcal 我希望 tableview 数据滚动,但由于 tableview 从屏幕中间开始,我希望能够滚动整个屏幕,而不仅仅是从 tableview 开始的地方

标签: swift scroll tableview


【解决方案1】:

试试这个:

在情节提要中选择您的表格视图并关闭启用滚动(在属性检查器的滚动视图部分下)。

或者,将其放入您的 TableViewController viewDidLoad:

tableView.isScrollEnabled = false

【讨论】:

    【解决方案2】:

    我不知道你想要什么样的效果,但你可以像这样处理 tableView 的内容插入:

    import UIKit
    
    class ViewController : UIViewController {
    
    
        let tableView: UITableView = {
            let tv = UITableView()
            tv.backgroundColor = .green
            return tv
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
            title = "Scrolling"
    
            view.backgroundColor = .blue
    
    
    
            view.addSubview(tableView)
    
            tableView.frame = view.frame
    
            let SCREENH = UIScreen.main.bounds.height
    
            tableView.contentInset = UIEdgeInsets(top: SCREENH/2, left: 0, bottom: 0, right: 0)
    
            tableView.delegate = self
            tableView.dataSource = self
    
        }
    
    }
    
    extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 20
        }
    
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = UITableViewCell()
            cell.textLabel?.text = "Cell \(indexPath.row)"
            return cell
        }
    
    }
    

    或者如果您在 tableView 顶部有内容并且不希望 contentInset 方法给出的效果,为什么不为您的 tableView 实现一个标题并将您的信息放在那里。

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      最简单的选择是在 Storyboard 中选择 TableView,然后点击属性。在那里你会发现复选框“Scrolling Enabled”只需取消选中该复选框,然后禁用 tableview 的滚动。

      如果你澄清我是哪个容器(scrollView 或你用作 SuperView 的任何其他东西),我能帮你更多吗

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-15
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        相关资源
        最近更新 更多