问题描述
我遇到的一个问题是,滚动到嵌入在UIViewController内的UITableView时,大标题导航栏会突然崩溃.似乎仅在屏幕上滚动时会出现此问题.在屏幕上向下滚动时,标题会平滑过渡到再次变大,反之亦然.
I'm facing an issue where the large title navigation bar collapses very abruptly when scrolling on a UITableView embedded inside of a UIViewController. The problem seems to only occur when scrolling up on the screen. When scrolling down on the screen, the title transitions smoothly to being big again, but not vice versa.
如果使用UITableViewController,则不会发生此问题.
This issue does NOT occur if using a UITableViewController.
这是在UITableViewController中滚动时的正常预期行为.
Here is the normal, expected behavior when scrolling inside a UITableViewController.
这是在UIViewController内使用UITableView时断断续续的过渡.
And here is the broken, abrupt transition when using a UITableView inside of a UIViewController.
这是坏了的实现的代码:
Here is the code for the broken implementation:
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
}
}
导航栏已选中首选大标题,并且导航项已将大标题设置为自动.
The Navigation Bar has Prefers Large Titles checked and the Navigation Item has Large Title set to Automatic.
上面两个示例的代码和配置完全相同,除了一个是UITableViewController与UIViewController内部的UITableView.
The code and configuration for both examples above is exactly the same except for the one being a UITableViewController vs. a UITableView inside of a UIViewController.
我还观察到,如果UITableView的内容不超过视图的高度,则不会发生损坏的行为.但是,一旦屏幕上的单元格超出容纳空间,它就会破裂.
I have also observed that the broken behavior does NOT occur if the contents of the UITableView does not exceed the view's height. But once there are more cells than can fit on screen, it breaks.
知道我做错什么了吗,或者这是iOS 11的错误吗?
Any idea if I'm doing something wrong or if this is an iOS 11 bug?
推荐答案
我遇到了同样的问题-我在 UINavigationController
中嵌入了 UIViewController
,即 UIViewController 代码>的表视图具有到安全区域的前,后,上,下约束.整个tableview表现跳动/活泼.诀窍是将表视图的顶部约束更改为 superview .
I faced same issue - I had UIViewController
embedded in UINavigationController
, the UIViewController
had tableview with leading, trailing, top, bottom constraints to safe area. The whole tableview behaved jumpy / snappy. The trick was to change top constraint of tableview to superview.
在这里,我记录了更改约束的情况 tableview iOS 11错误约束更改
Here I recorded changing the constrainttableview iOS 11 bug constraint change
这篇关于iOS 11大标题导航栏会捕捉而不是平滑过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!