在第一次加载时显示 collectionView 的底部,无需滚动和延迟加载

Show the bottom of collectionView on first load without scrolling and lazy loading

我开发了一个聊天应用程序,我在 iOS 应用程序中使用了 MessageKit。我的问题是当我打开任何聊天屏幕时,messageCollectionView 从顶部开始,显示旧聊天。我需要在打开任何聊天屏幕后立即从底部启动 collectionView。 我试过了:

messagesCollectionView.scrollToBottom(动画:真)

但会对性能产生影响(如果消息超过 hundreds/thousands)。

有什么方法可以反转集合视图,或者从底部开始添加单元格,然后从顶部开始添加。

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)
   }