我有一个 UITableView
占据整个屏幕框架的标题。
每次应用程序进入后台,然后返回前台/事件时,我希望屏幕设置回标题顶部。
我只看到与滚动到表格顶部有关的答案,类似这些 answers使用类似 self.tableView.scrollToRow(at: top, at: .top, animated: true)
的东西,但这不起作用,因为它只会滚动回 UITableView
的第 0 节第 0 行|不是 UITableView
标题的顶部.
有什么想法吗?
谢谢!
编辑:试过这个
override func viewWillAppear(_ animated: Bool) {
self.tableView.setContentOffset( CGPoint(x: 0, y: 0) , animated: true)
}
下面是一些值得注意的表格设置代码:
// Set up Frames
let headerFrame: CGRect = UIScreen.main.bounds
// Background Table
self.tableView.isPagingEnabled = true
// Set up Table Header
let header = UIView(frame: headerFrame)
self.tableView.tableHeaderView = header
最佳答案
TableView 是一个 ScrollView 子类,所以我想这应该可行:
self.tableView.setContentOffset( CGPoint(x: 0, y: 0) , animated: true)
当应用程序进入前台时,不会调用 ViewWillAppear。为 UIApplicationWillEnterForegroundNotification
关于ios - 滚动到 TableView 标题顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40204390/