首页 > 解决方案 > 如何在 SWIFT 中更改 ViewController 后保留集合视图滚动位置

问题描述

问题是:滚动collectionView 并单击一个项目后,另一个viewController 通过navigationController 呈现。当我点击“返回”按钮(左上角)时,集合视图会滚动到顶部,但我希望它保持更改视图控制器之前的“滚动位置”。

我尝试添加
自动AdjustsScrollViewInsets = false

谢谢

标签: swiftcollectionview

解决方案


automaticallyAdjustsScrollViewInsets has nothing to do with what you are dealing with. The collectionView should not scroll back to top by itself. You are probably calling reloadData() in viewDidAppear or viewWillAppear which triggers the behavior you are describing.


推荐阅读