我遇到了一个问题,即在 UIViewController 内嵌的 UITableView 上滚动时,大标题导航栏会突然折叠。该问题似乎只在屏幕上向上滚动时出现。在屏幕上向下滚动时,标题会平滑地再次变大,但反之则不然。
如果使用 UITableViewController,则不会出现此问题。
这是在 UITableViewController 中滚动时正常的预期行为。
这是在 UIViewController 中使用 UITableView 时中断的、突然的过渡。
这里是错误实现的代码:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 12
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Basic", for: indexPath)
cell.textLabel?.text = "Title \(indexPath.row)"
return cell
}
}
导航栏已选中Prefers Large Titles,导航项已将Large Title设置为Automatic。
除了一个是 UITableViewController 还是一个 UIViewController 内部的 UITableView 之外,上面两个示例的代码和配置完全相同。
我还观察到,如果 UITableView 的内容不超过 View 的高度,则不会发生损坏的行为。但是一旦单元格多于屏幕上无法容纳的单元格,它就会崩溃。
如果我做错了什么或者这是一个 iOS 11 错误,你知道吗?
最佳答案
我遇到了同样的问题 - 我将 UIViewController
嵌入到 UINavigationController
中,UIViewController
的 TableView 带有前导、尾随、顶部、底部约束安全区域。整个 TableView 表现得神经质/活泼。诀窍是将 tableview 的顶部约束更改为 superview。
关于swift - iOS 11 大标题导航栏卡住而不是平滑过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48039046/