当我的 MSMessagesAppViewController 将presentationStyle从 compact
更改时至expanded
并返回compact
,我的 UITableView 的滚动困惑了。
我正在使用 AutoLayout 设置 UITableView
在名为 contentView
的 View 内部。
// Inside MSMessagesAppViewController
func createTableView() {
let tableViewController = MyTableViewController()
self.addChildViewController(tableViewController)
tableViewController.tableView.backgroundColor = UIColor.clear
tableViewController.tableView.translatesAutoresizingMaskIntoConstraints = false
self.contentView.addSubview(tableViewController.tableView)
NSLayoutConstraint.activate([
tableViewController.tableView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
tableViewController.tableView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 0),
tableViewController.tableView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0),
tableViewController.tableView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0)
])
}
展开和折叠 MSMessagesAppViewController 后,我可以突然滚动到 tableView 中的最后一个单元格...
在初始状态下一切都工作得很好。我注意到,滚动条在启动时可见,但在大小更改后不存在......
这就是我在 Controller 中设置 tableView 的方式:
// Inside MyTableViewController
func setupTableView() {
tableView.dataSource = self
tableView.register(QuickStandardTableViewCell.self, forCellReuseIdentifier: "standardCell")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 64
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.separatorColor = .clear
tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
tableView.estimatedSectionHeaderHeight = 8.0
self.extendedLayoutIncludesOpaqueBars = false
}
我检查的内容:
- contentView 框架正确更改
- tableView框架正确变化
- contentInset 不变
- 内容大小不变
有人知道我错过了什么吗?
提前致谢!
最佳答案
尝试使用内部带有 UITableView
的 UIViewController
,而不是使用 UITableViewController
。
我在使用 UICollectionViewController
时遇到了同样的问题,并切换到 UIViewController
解决了这个问题。
关于ios - MSMessagesAppViewController 搞乱了 UITableViewController 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49223657/