單擊消息後的 MessageKit 動畫 (MessageKit animation after click on message)


問題描述

單擊消息後的 MessageKit 動畫 (MessageKit animation after click on message)

我嘗試在我的應用程序中添加相同的動畫,我們可以在信使中找到,點擊一些消息後,應用程序顯示日期標籤。我可以顯示這個日期,但我不能添加流暢的動畫。我嘗試添加 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])
}

點擊前




<hr>




<h2>參考解法</h2>

<h4>方法 1:</h4> <p>First: You should create an array [IndexPath] to save indexPath of messages you tapped in</p>
<pre><code>func didTapMessage(in cell: MessageCollectionViewCell) 
</code></pre>
<p>Second: You should use some function of MessagesLayoutDelegate protocol and MessagesDataSource protocol to set height or content for top, bottom message such as Date time, status message, ...</p>
<pre><code> 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?
</code></pre>
<p>In there function, will check indexPath equal your saved indexPath tapped to show or hide Date time. It's up to your logical.</p><p>(by <a href=TrikerHHumorous)

參考文件

  1. MessageKit animation after click on message (CC BY‑SA 2.5/3.0/4.0)

#animation #iOS #XCode #swift #messagekit






相關問題

Iphone app PNG 序列動畫 - 如何在不崩潰的情況下以最佳方式使用 OPENgle (Iphone app PNG sequence animation - How to use OPENgle optimally without crashing)

jquery切換幻燈片和切換旋轉動畫 (jquery toggle slide and toggle rotation animate)

如何在三次貝塞爾方法上禁用 css3 過渡鼠標離開效果? (How to disable css3 transition mouseleave effect on cubic-bezier method?)

Android:故事書(動畫、聲音、圖片) (Android: Storybooks (animation, sounds, pictures))

JQuery 動畫凌亂 (JQuery Animations Messy)

拉斐爾對角變換對象和無限setIntervals (Raphael transform object diagonally and infinite setIntervals)

使用 mouseover 和 mouseout 時避免生澀的動畫 (Avoiding jerky animation when using mouseover and mouseout)

在 C 中復制 Spinrite 動畫效果 (Replicating Spinrite Animation Effect in C)

將樣式作為參數傳遞給 jquery animate (passing style as argument to jquery animate)

如何設置 UIButton 的圖像並隨後將其刪除(動畫) (How to setImage of a UIButton and subsequently remove it (animation))

單擊消息後的 MessageKit 動畫 (MessageKit animation after click on message)

連續貝塞爾動畫,不繼承變化時的緩動功能 (Continuous bezier animation without inheriting easing-function on change)







留言討論