0

my messageViewController of Messagekit is showing messages like this , how can i set offset of messages to show below the navigation bar ?

enter image description here

my code for messageViewController Layout

 func configureView(){

    scrollsToBottomOnKeyboardBeginsEditing = true // default false
    maintainPositionOnKeyboardFrameChanged = true // default false

let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout
layout?.sectionInset = UIEdgeInsets(top: 1, left: 8, bottom: 1, right: 8)

// Hide the outgoing avatar and adjust the label alignment to line up with the messages
layout?.setMessageOutgoingAvatarSize(.zero)
layout?.setMessageOutgoingMessageTopLabelAlignment(LabelAlignment(textAlignment: .right, textInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)))
layout?.setMessageOutgoingMessageBottomLabelAlignment(LabelAlignment(textAlignment: .right, textInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)))

// Set outgoing avatar to overlap with the message bubble
layout?.setMessageIncomingMessageTopLabelAlignment(LabelAlignment(textAlignment: .left, textInsets: UIEdgeInsets(top: 0, left: 18, bottom: outgoingAvatarOverlap, right: 0)))
layout?.setMessageIncomingAvatarSize(CGSize(width: 30, height: 30))
layout?.setMessageIncomingMessagePadding(UIEdgeInsets(top: -outgoingAvatarOverlap, left: -18, bottom: outgoingAvatarOverlap, right: 18))

layout?.setMessageIncomingAccessoryViewSize(CGSize(width: 30, height: 30))
layout?.setMessageIncomingAccessoryViewPadding(HorizontalEdgeInsets(left: 8, right: 0))
layout?.setMessageIncomingAccessoryViewPosition(.messageBottom)
layout?.setMessageOutgoingAccessoryViewSize(CGSize(width: 30, height: 30))
layout?.setMessageOutgoingAccessoryViewPadding(HorizontalEdgeInsets(left: 0, right: 8))

messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
}

If I hide the navigation bar it shows like this

enter image description here

Hanzala Raza
  • 149
  • 1
  • 16
  • try to set `contentInset` for `messagesCollectionView` in `viewDidLayoutSubviews()` `self.messagesCollectionView.contentInset = UIEdgeInsets(top: 70, left: 0, bottom: 70, right: 0)` – Kishan Bhatiya Aug 26 '20 at 10:38

3 Answers3

3

Are you using IQKeyboardManager?

If so then you can fix the issue simply by adding this in AppDelegate didFinishLaunchingWithOptions:

IQKeyboardManager.shared.disabledDistanceHandlingClasses.append(YourChatVC.self)

Ali Elsokary
  • 108
  • 1
  • 10
  • 1
    It seems like this could be the solution :) .... Thanks alot for this .. will surely gonna try this whenever I implement this again (Y) – Hanzala Raza Feb 08 '21 at 12:02
1

Add content inset padding to messagesCollectionView

override func viewDidLoad() {
    super.viewDidLoad()

   self.messagesCollectionView.contentInset = UIEdgeInsets(top: 70, left: 0, bottom: 70, right: 0)
}
Jan
  • 1,744
  • 3
  • 23
  • 38
0

You need to change messagesCollectionView contentSize in viewDidLayoutSubviews