iOS 11大标题导航栏快照而不是平滑过渡

Vil*_*zed 25 xcode uitableview uiviewcontroller swift ios11

我正面临一个问题,当在UIViewController内部嵌入的UITableView上滚动时,大标题导航栏会突然崩溃.问题似乎只发生在屏幕上向上滚动时.当在屏幕上向下滚动时,标题会平滑过渡到再次变大,但反之则不然.

如果使用UITableViewController,则不会发生此问题.

这是在UITableViewController内滚动时的正常预期行为.

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

当在UIViewController中使用UITableView时,这是一个破碎的,突然的转换.

iOS 11 UITableViewController(正确转换)

以下是破坏实现的代码:

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
    }

}
Run Code Online (Sandbox Code Playgroud)

导航栏优先选中大标题,导航项将大标题设置为自动.

上面两个示例的代码和配置完全相同,除了一个是UITableViewController与UIViewController内的UITableView.

我还观察到,如果UITableView的内容不超过视图的高度,则不会发生破坏的行为.但是,一旦有更多的细胞可以放在屏幕上,它就会破裂.

不知道我做错了什么或者这是iOS 11的错误吗?

小智 40

我遇到了同样的问题 - 我在UINavigationController中嵌入了UIViewController,UIViewController具有对安全区域有前导,尾随,顶部,底部约束的tableview .整个tableview表现得很好/有趣.诀窍是将tableview的顶级约束更改为superview.

这里我记录了更改约束 tableview iOS 11的bug约束更改


Fil*_*ppo 30

把这行代码放在包含UITableView的UIViewController上,对我来说效果很好.

迅速

extendedLayoutIncludesOpaqueBars = true;
Run Code Online (Sandbox Code Playgroud)

Objective-C的

self.extendedLayoutIncludesOpaqueBars = YES;
Run Code Online (Sandbox Code Playgroud)

将UITableView AutoLayout顶部空间设置为"Superview"而不是"Safe Area"

  • 当我的导航控制器包含在选项卡控制器中时,这会导致我的安全区域出现问题。有了这个,我的表格视图不会考虑由标签栏创建的底部安全区域。 (3认同)

fl0*_*034 6

我有一个类似的问题,并通过UINavigationBar.appearance().isTranslucent = false 从我的 AppDelegate 中删除来解决它。

更新:如果你不想要半透明,你应该启用extendedLayoutIncludesOpaqueBars. 这样所有的故障都修复了。