简体   繁体   English

iOS 11 大标题导航栏捕捉而不是平滑过渡

[英]iOS 11 large title navigation bar snaps instead of smooth transition

I'm facing an issue where the large title navigation bar collapses very abruptly when scrolling on a UITableView embedded inside of a UIViewController.我面临一个问题,当滚动嵌入 UIViewController 内的 UITableView 时,大标题导航栏会非常突然地折叠。 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.在屏幕上向下滚动时,标题会平滑地再次变大,但反之则不然。

This issue does NOT occur if using a UITableViewController.如果使用 UITableViewController,则不会发生此问题。

Here is the normal, expected behavior when scrolling inside a UITableViewController.这是在 UITableViewController 中滚动时的正常预期行为。

UIViewController 中的 iOS 11 UITableView(滚动时中断的突然转换)

And here is the broken, abrupt transition when using a UITableView inside of a UIViewController.这是在 UIViewController 中使用 UITableView 时出现的中断的、突然的转换。

iOS 11 UITableViewController(正确过渡)

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.导航栏选中了首选大标题,导航项的大标题设置为自动。

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.上面两个示例的代码和配置完全相同,除了一个是 UITableViewController 与 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.我还观察到,如果 UITableView 的内容不超过视图的高度,则不会发生损坏的行为。 But once there are more cells than can fit on screen, it breaks.但是一旦有更多的单元格超过了屏幕上的容量,它就会崩溃。

Any idea if I'm doing something wrong or if this is an iOS 11 bug?知道我做错了什么还是这是 iOS 11 的错误?

I faced same issue - I had UIViewController embedded in UINavigationController , the UIViewController had tableview with leading, trailing, top, bottom constraints to safe area .我面临着同样的问题-我UIViewController嵌入UINavigationControllerUIViewController有tableview中与前置,顶部,底部制约安全区域 The whole tableview behaved jumpy / snappy.整个 tableview 表现得活泼/活泼。 The trick was to change top constraint of tableview to superview .诀窍是将 tableview 的顶部约束更改为superview

Here I recorded changing the constraint tableview iOS 11 bug constraint change这里我记录了更改约束tableview iOS 11 bug 约束更改

Put this line of code on your UIViewController containing UITableView and works fine for me.将这行代码放在包含 UITableView 的 UIViewController 上,对我来说效果很好。

Swift斯威夫特

extendedLayoutIncludesOpaqueBars = true;

Objective-C目标-C

self.extendedLayoutIncludesOpaqueBars = YES;

Set UITableView AutoLayout top space to "Superview" instead of "Safe Area"将 UITableView AutoLayout 顶部空间设置为“Superview”而不是“Safe Area”

I had a similar looking issue and solved it by removing UINavigationBar.appearance().isTranslucent = false from my AppDelegate.我有一个类似的问题,并通过从我的 AppDelegate 中删除UINavigationBar.appearance().isTranslucent = false来解决它。

UPDATE: If you don't want translucency, you should enable extendedLayoutIncludesOpaqueBars .更新:如果你不想要半透明,你应该启用extendedLayoutIncludesOpaqueBars That way all the glitches are fixed.这样所有的故障都修复了。

In Interface Builder:在界面生成器中:

  1. Select your "viewController".选择您的“视图控制器”。
  2. Attribute Inspector tick "Under Opaque Bars" and "Under Top Bars".属性检查器勾选“在不透明条下”和“在顶部条下”。
  3. Make your top constraints of your scrollView second Item to "SuperView" not "SafeArea".将 scrollView 第二项的最高约束设置为“SuperView”而不是“SafeArea”。

It worked with me.它和我一起工作。

Reference参考

Soolar's answer is right, but I don't know how to fix it in storyboard. Soolar 的回答是正确的,但我不知道如何在故事板中修复它。 Finally I solved the problem with Roman's solution in another question, by adding:最后我在另一个问题中用 Roman 的解决方案解决了这个问题,添加:

NSLayoutConstraint.activate([
    scrollView.topAnchor.constraint(equalTo: view.topAnchor),
    scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),
    scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
    scrollView.rightAnchor.constraint(equalTo: view.rightAnchor)
])

in viewDidLoad .viewDidLoad

Original answer: https://stackoverflow.com/a/48321447/1386369原答案: https : //stackoverflow.com/a/48321447/1386369

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM