Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在JSQMessagesViewController中居中放置消息气泡_Ios_Swift_Uicollectionview_Jsqmessagesviewcontroller - Fatal编程技术网

Ios 如何在JSQMessagesViewController中居中放置消息气泡

Ios 如何在JSQMessagesViewController中居中放置消息气泡,ios,swift,uicollectionview,jsqmessagesviewcontroller,Ios,Swift,Uicollectionview,Jsqmessagesviewcontroller,我的目标是在JSQMessagesViewController中有一条“叙述”消息。我希望此消息集中在屏幕上。我试图通过居中消息气泡容器(包含气泡和文本)来居中消息。这是我的代码: class MessagesViewController: JSQMessagesViewController override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: N

我的目标是在JSQMessagesViewController中有一条“叙述”消息。我希望此消息集中在屏幕上。我试图通过居中消息气泡容器(包含气泡和文本)来居中消息。这是我的代码:

class MessagesViewController: JSQMessagesViewController

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell
        let message = messages[indexPath.row]

        // Sent message
        if message.senderId() == self.senderId {
            // Normal outgoing message

        }
        // Narration Message
        else if message.senderId() == Constants.lbSenderName {
            cell.textView?.textAlignment = NSTextAlignment.Center

            // new frame -- isn't changing the frame.
            let newX = (cell.frame.width - (cell.messageBubbleContainerView?.frame.width)!)/2.0
            cell.messageBubbleContainerView?.frame = CGRectMake(
                newX,
                (cell.messageBubbleContainerView?.frame.minY)!,
                (cell.messageBubbleContainerView?.frame.width)!,
               (cell.messageBubbleContainerView?.frame.height)!
           )
        }
        // Received message
        else {
            // Normal incoming message
        }

        return cell
    }

}
细胞根本没有像我所期望的那样移动。我试过使用

cell.messageBubbleContainerView?.translatesAutoresizingMaskIntoConstraints = true
但这会让泡沫消失。任何建议,无论是像我正在做的那样手动更改布局,还是通过JSQMessagesViewController使用,我都将不胜感激


我希望它看起来像这样:

这个库当前不支持。上面的代码没有任何更改,因为这些更改会立即被库覆盖

目前唯一想实现这一点的是提供您自己的cell子类。您可以在集合视图中注册单元格,然后设置
传入
传出
单元格标识符属性


相关文档:

我建议您将JSQMessageCollectionViewCell子类化,并为您的应用程序添加合适的布局。我在警告:您不应尝试操作此视图的任何属性,例如调整其框架,也不应从单元格中删除此视图或其任何子视图。这样做可能会导致意外行为。“这是有道理的。但我不确定如果我只需要文本,我是应该子类化JSQMessageCollectionViewCell,还是应该子类化CollectionViewCell?你能提供一个代码片段来实现吗?我需要在情节提要中创建单元吗?