0

我的 Messagekit 的messageViewController正在显示这样的消息,我如何设置消息的偏移量以显示在导航栏下方?

在此处输入图像描述

我的 messageViewController 布局代码

 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
}

如果我隐藏导航栏,它会像这样显示

在此处输入图像描述

4

3 回答 3

3

你在使用IQKeyboardManager吗?

如果是这样,那么您只需将其添加到以下内容即可解决问题AppDelegate didFinishLaunchingWithOptions

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

于 2021-02-04T18:38:58.670 回答
1

向 messagesCollectionView 添加内容插入填充

override func viewDidLoad() {
    super.viewDidLoad()

   self.messagesCollectionView.contentInset = UIEdgeInsets(top: 70, left: 0, bottom: 70, right: 0)
}
于 2020-08-09T17:41:12.807 回答
0

您需要在 viewDidLayoutSubviews 中更改 messagesCollectionView contentSize

于 2022-02-05T06:56:26.290 回答