0

I am using messageKit show messages,video and photo in a text format and all the messages are predefined. When user taps on the screen it, should show the next message. I have added gesture recognizer to messageCollectionView but when the user taps on the image, i need to show the image in full screen. But the cell delegate is never called

   let gesture = UITapGestureRecognizer(target: self, action: #selector(MessageViewController.tapScreen(_:)))

    messagesCollectionView.addGestureRecognizer(gesture)
    messagesCollectionView.messagesDataSource = self
    messagesCollectionView.messagesLayoutDelegate = self
    messagesCollectionView.messagesDisplayDelegate = self
    messagesCollectionView.messageCellDelegate = self

I am using the lates messageKit

pod 'MessageKit'

Any idea how i can achieve this?

To further clarify, here is an image of the screen. Clicking anywhere should call the gesture function, but image should call the cellDelegate.

enter image description here

Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100
Asif Alamgir
  • 1,454
  • 1
  • 16
  • 41
  • https://stackoverflow.com/questions/27880607/how-to-assign-an-action-for-uiimageview-object-in-swift/53809261#53809261 -> use that tap gesture on UIView, UIImageView and all child of UIView etc. – Ravindra_Bhati Jan 31 '19 at 17:37

2 Answers2

1

You can call this method provided by Messagekit it self.

 extension ViewController: MessageCellDelegate {

func didTapAvatar(in cell: MessageCollectionViewCell) {
    print("Avatar tapped")
}

func didTapMessage(in cell: MessageCollectionViewCell) {
 // handle message here
 print("Meesage Tapped")
 }
Suresh Mopidevi
  • 919
  • 3
  • 9
  • 24
0

In the ChatViewController in viewDidLoad before the super.viewDidLodad call. You can add:

 override func viewDidLoad() {
    let tapGesture = UITapGestureRecognizer(target: self, action: 
    #selector(cellTapped(sender:)))
        tapGesture.cancelsTouchesInView = false
        messagesCollectionView.addGestureRecognizer(tapGesture)
     super.viewDidLoad()
    }

    @objc
    private func cellTapped(sender: UITapGestureRecognizer) {
        // Do Something
    }

Or you can use the already provided function in the MessageCellDelegate

func didTapImage(in cell: MessageCollectionViewCell) {}
Mark Thomas
  • 35
  • 1
  • 7