0

我尝试在我的应用程序中添加相同的动画,我们可以在信使中找到,点击一些消息后,应用程序显示日期标签。我可以显示这个日期,但我不能添加流畅的动画。我尝试添加 uiview.animate(withDuration),但在我阅读的另一个主题中,我需要调用方法 layoutIfNeed,但我无法处理来自 messagekit 的任何对象。有人可以帮助我,或者给我另一种方法来做这个滑动动画

func didTapMessage(in cell: MessageCollectionViewCell) {
    if isClicked {
        isClicked = false
        if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
            layout.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        }
    } else {
        isClicked = true
        if let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {
            UIView.animate(withDuration: 3) {
                //MARK: how called layoufIfNeeded()? or how do this animation another way
                layout.collectionView?.layoutIfNeeded()
                layout.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0))
            }
        }
    }
    let indexPath = self.messagesCollectionView.indexPath(for: cell)!
    messagesCollectionView.reloadItems(at: [indexPath])
}

点击前点击后

4

1 回答 1

0

首先:您应该创建一个数组 [IndexPath] 来保存您点击的消息的 indexPath

func didTapMessage(in cell: MessageCollectionViewCell) 

第二:您应该使用 MessagesLayoutDelegate 协议和 MessagesDataSource 协议的某些功能来设置顶部,底部消息的高度或内容,例如日期时间,状态消息,...

 func cellTopLabelHeight(for message: MessageKit.MessageType, at indexPath: IndexPath, in messagesCollectionView:
    MessageKit.MessagesCollectionView) -> CGFloat
        func messageTopLabelHeight(for message: MessageKit.MessageType, at indexPath: IndexPath, in messagesCollectionView:
    MessageKit.MessagesCollectionView) -> CGFloat

func cellTopLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?
 func cellBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString?

在该函数中,将检查 indexPath 是否等于您保存的 indexPath 点击以显示或隐藏日期时间。这取决于你的逻辑。

于 2020-07-17T08:31:41.187 回答