我开发了一个聊天应用程序,我在其中将 MessageKit 用于我的 iOS 应用程序。我的问题是当我打开任何聊天屏幕时,messageCollectionView 从顶部开始,显示旧聊天。我需要在打开任何聊天屏幕后立即从底部启动 collectionView。 我试过了:
messagesCollectionView.scrollToBottom(动画:真)
但是会对性能产生影响(如果有超过数百/数千条消息)。
如果反转 Collection View ,或者开始从底部然后顶部添加单元格,有什么办法。
最佳答案
The above suggestions in comments were more robust and correct implementation.
或者你可以试试这个:
//After reloading
DispatchQueue.main.async {
self.messagesCollectionView.scrollToItem(at: IndexPath(row: 0, section: self.messages.count - 1), at: .top, animated: false)
}
关于ios - 在第一次加载时显示 collectionView 的底部,无需滚动和延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58761365/