ios - UICollectionView scrollToItem 在 iOS 14 中不起作用
问题描述
我正在使用集合视图 UICollectionView,它工作得非常好……除了我无法滚动到任何特定项目。它似乎总是滚动到“中间”是我最好的猜测。无论如何,我发送给 scrollToItem 的任何内容似乎都对滚动没有影响。我已将它放在整个视图控制器的各个位置,但没有成功。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let lastIndex = IndexPath(row: messages.count-1, section: 0)
self.messagesView.scrollToItem(at: lastIndex, at: .bottom, animated: true)
}
解决方案
UICollection View 在 iOS 14 中带有scrollToItem的错误。在 iOS 14 中,它仅在集合视图分页禁用时才有效。因此,如果我们必须以手动和编程方式滚动,我得到了一个解决方案。
特别适用于 iOS 14 及更高版本
self.collView.isPagingEnabled = false
self.collView.scrollToItem(at: IndexPath(item: scrollingIndex, section: 0), at: .left, animated: true)
self.collView.isPagingEnabled = true
推荐阅读
- php - 致命错误:未捕获的错误:调用未定义的函数
- cakephp - 如何在控制器 cakephp 1.3 中获取视图 html
- r - 基于多个变量重新编码单个变量
- solr - apache solr 配置 - 如何在 VCS 中保留配置,但在机器上保留数据
- navigation - 我可以使用导航自定义模式吗?
- ios - ld: 找不到 -lDoubleConversion React Native 0.59 的库
- html - Safari 中的锚链接...?
- c# - Scaleout webhook 注册
- alignment - Latex 错误缺少 { 已插入。\结束{对齐}?
- javascript - 角材料输入模式添加空白