如何在 MessageKit 的 messagesCollectionView 之上添加一个 UIView

How to add a UIView on top of MessageKit's messagesCollectionView

我正在尝试在 messagesCollectionView 之上添加一个 UIView,但是 collectionview 似乎占据了整个屏幕,使得我想添加的 UIView 无法被看到。我在这里查看他们的文档:https://github.com/MessageKit/MessageKit/blob/master/Sources/Layout/MessagesCollectionViewFlowLayout.swift

我的想法是更改布局委托中的某些内容,但我不确定更改的内容和位置...任何对此的想法都将不胜感激!

谢谢!

如果你想在 messagesCollectionView 上方有某种浮动视图,那么你可以将它作为子视图添加到 MessagesViewControlerview,只需确保这样做 after 你调用了 super.viewDidLoad() 因为这是 MessageKit 将 collectionView 添加为子视图的地方所以如果你在此之前添加它,那么你的视图将在 collectionView 后面并且不会出现.为防止单元格与您的视图重叠,如果您的视图浮动在那里,您可以使用 messagesCollectionView.contentInset 属性 向顶部或底部添加填充,以便用户仍然可以滚动到所有消息.像这样:

    override func viewDidLoad() {
        super.viewDidLoad()
        let subview = UIView()
        view.addSubview(subview)
        // Either add constraints or set the frame manually
        // ...
        // Set the contentInset if you want to prevent the messages from overlapping your view
        messagesCollectionView.contentInset.top = 10 // For example, if your view was stickied to the top and was height 10px
    }

您可以采用的另一条路线是拥有一个父视图控制器,您可以在其中将 MessagesViewController 作为子项 VC 添加到父项,然后根据需要调整 messagesCollectionView 的大小和布局。您可以在 MessageContainerController class 中的 MessageKit 示例应用程序中看到这样的示例:https://github.com/MessageKit/MessageKit/blob/master/Example/Sources/View%20Controllers/MessageContainerController.swift