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

3
1个回答

3
如果你想在messagesCollectionView上方添加一种浮动视图,你可以将它作为子视图添加到MessagesViewController的视图中,但是要确保在调用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添加到父视图控制器中,然后按照您的要求对消息收集视图进行大小和布局。您可以在MessageKit示例应用程序的MessageContainerController类中看到此示例:https://github.com/MessageKit/MessageKit/blob/master/Example/Sources/View%20Controllers/MessageContainerController.swift

太棒了,非常感谢您的回答!所以我已经实现了它浮动在上方,因此从技术上讲,消息通过屏幕顶部滚动,是否有类似插图的东西可以使用,以便我可以使用偏移量(如85)来防止消息超过顶部滚动? - Wana_B3_Nerd

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接