iOS11中奇怪的uitableview行为。单元格向上滚动导航推送动画 [英] Weird uitableview behaviour in iOS11. Cells scroll up with navigation push animation

查看:78
本文介绍了iOS11中奇怪的uitableview行为。单元格向上滚动导航推送动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将一些代码迁移到新的iOS 11 beta 5 SDK。

I have recently migrated some code to new iOS 11 beta 5 SDK.

我现在从UITableView获得了一个非常令人困惑的行为。 tableview本身并不那么花哨。我有自定义单元格,但大部分只是它们的高度。

I now get a very confusing behaviour from UITableView. The tableview itself is not that fancy. I have custom cells but in most part it is just for their height.

当我用tableview推动我的视图控制器时,我得到一个额外的动画,其中单元格向上滚动(或者可能整个tableview框架已更改)并沿着推/弹导航动画向下。请参阅gif:

When I push my view controller with tableview I get an additional animation where cells "scroll up" (or possibly the whole tableview frame is changed) and down along push/pop navigation animation. Please see gif:

我手动创建 tableview loadView 方法和设置自动布局约束等于tableview的superview的leading,trailing,top,bottom。 superview是视图控制器的根视图。

I manually create tableview in loadView method and setup auto layout constraints to be equal to leading, trailing, top, bottom of tableview's superview. The superview is root view of view controller.

查看控制器推送代码非常标准: self.navigationController?.pushViewController(notifVC,animated: true)

View controller pushing code is very much standard: self.navigationController?.pushViewController(notifVC, animated: true)

相同的代码在iOS 10上提供正常行为。

The same code provides normal behaviour on iOS 10.

可以你能指出我的错误方向吗?

Could you please point me into direction of what is wrong?

编辑:我制作了一个非常简单的tableview控制器,我可以在那里重现相同的行为。代码:

I have made a very simple tableview controller and I can reproduce the same behavior there. Code:

class VerySimpleTableViewController : UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    }


    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

        cell.textLabel?.text = String(indexPath.row)
        cell.accessoryType = .disclosureIndicator

        return cell
    }


    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)

        let vc = VerySimpleTableViewController.init(style: .grouped)

        self.navigationController?.pushViewController(vc, animated: true)
    }
}

编辑2:我能够缩小范围发布到我的UINavigationBar自定义。我有这样的自定义:

EDIT 2: I was able to narrow issue down to my customisation of UINavigationBar. I have a customisation like this:

rootNavController.navigationBar.setBackgroundImage(createFilledImage(withColor:.white,size:1),用于:.default )

其中 createFilledImage 创建具有给定大小和颜色的方形图像。

where createFilledImage creates square image with given size and color.

如果我注释掉这一行,我会恢复正常行为。

If I comment out this line I get back normal behaviour.

我将不胜感激任何有关此问题的想法。

I would appreciate any thoughts on this matter.

推荐答案

这是由于 UIScrollView的 (UITableView是一个子类UIScrollview)新的 contentInsetAdjustmentBehavior 属性,设置为 .automatic 默认情况下。

This is due to UIScrollView's (UITableView is a subclass of UIScrollview) new contentInsetAdjustmentBehavior property, which is set to .automatic by default.

您可以在任何受影响的控制器的viewDidLoad中使用以下代码段覆盖此行为:

You can override this behavior with the following snippet in the viewDidLoad of any affected controllers:

    tableView.contentInsetAdjustmentBehavior = .never

https://developer.apple.com/documentation/uikit/uiscrollview/2902261-contentinsetadjustmentbehavior

这篇关于iOS11中奇怪的uitableview行为。单元格向上滚动导航推送动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆