【发布时间】:2023-03-22 15:53:01
【问题描述】:
单击UICollectionViewCell 时,我的UICollectionView 总是向上滚动一点。
我注意到如果我将集合视图插图设置为 0(根本没有插图)并将 contentInsetAdjustmentBehavior 设置为 .never,则不会发生此行为。
但是,我仍然希望在我的 UICollectionView 上插入内容(底部和顶部各 8 像素),而无需自动滚动。我不确定为什么会发生这种行为以及它与 content inset 属性到底有什么关系。
有没有一种方法可以让自定义插图在点击UICollectionViewCell 时不会导致滚动?
这是我在viewDidLoad()中的配置:
self.collectionView?.contentInset = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
// self.collectionView?.contentInsetAdjustmentBehavior = .never
// When setting the contentInset to zero and the contentInsetAdjustmentBehavior to never, it does not scroll
VC 看起来像这样:
每个单元格代表一条消息。底部的视图是inputAccessoryView。
当我删除 inputAccessoryView 时,该行为不会发生。
这也可能与本次讨论有关:https://forums.developer.apple.com/thread/18424
【问题讨论】:
-
didSelectItemAtIndexPath函数中有什么代码? -
没什么@杰克。我只有一个自定义的
inputAccessoryView,它位于屏幕底部。 -
你的约束设置了吗?
-
访问
inputAccessoryView的高度并将CollectionView的底部约束设置为由inputAccessoryView的高度偏移的视图底部,这应该可以解决您的问题。 -
感谢@T.Meyer 乐于提供帮助。
标签: ios swift scroll uicollectionview uiedgeinsets