ios - JSQMessagesViewController incomingMessagesBubble 粘在右边

标签 ios swift jsqmessagesviewcontroller

我正在将 JSQMessagesViewController 用于聊天应用程序。 当我添加 incomingMessagesBubble 时,气泡会粘在屏幕的右侧。

import UIKit

class ChatViewController: JSQMessagesViewController, JSQMessagesCollectionViewDataSource, JSQMessagesCollectionViewDelegateFlowLayout {


var dataList: [JSQMessage] = []

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    self.senderId = "ME";
    self.senderDisplayName = "123256789";
    automaticallyScrollsToMostRecentMessage = true

    //dataList.append(JSQMessage(senderId: "Ilan", senderDisplayName: "ilandbt", date: NSDate(), text: "HelpMe"))
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    collectionView.collectionViewLayout.springinessEnabled = true
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

func senderDisplayName() -> String! {
    return "Ilan"
}

func senderId() -> String! {
    return "123256789"
}

override func didPressSendButton(button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: NSDate!) {
    JSQSystemSoundPlayer.jsq_playMessageSentSound()

    let message: JSQMessage = JSQMessage(senderId: senderId, senderDisplayName: senderDisplayName, date: date, text: text)

    dataList.append(message)
    self.finishSendingMessageAnimated(true)
}



override func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {

    return self.dataList[indexPath.row]
}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.dataList.count
}


override func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {

    //return JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor.jsq_messageBubbleRedColor())
    return JSQMessagesBubbleImageFactory().outgoingMessagesBubbleImageWithColor(UIColor.jsq_messageBubbleBlueColor())
}


override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {

    let diameter = UInt(collectionView.collectionViewLayout.outgoingAvatarViewSize.width)

    let image = UIImage(named: "defaultProfileImage")
    return JSQMessagesAvatarImageFactory.avatarImageWithImage(image, diameter: diameter)//nil//JSQMessageAvatarImageDataSource.
}

override func collectionView(collectionView: JSQMessagesCollectionView!, layout collectionViewLayout: JSQMessagesCollectionViewFlowLayout!, heightForCellTopLabelAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
    return kJSQMessagesCollectionViewCellLabelHeightDefault
}

我是否应该改变一些东西让它粘在左边?

谢谢

最佳答案

我的错误。 您需要更改传入发件人的发件人 ID。

关于ios - JSQMessagesViewController incomingMessagesBubble 粘在右边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28216021/

相关文章:

Swift - 捕获列表 self 澄清

ios - 意外发现 nil 错误,但所有值都存在

ios - 如何使用 JSQMessageViewController 使发件人显示名称出现?

objective-c - 应用内购买 "Invalid Product Identifier"错误信息

swift - 从 Swift 中的 block 返回 boolean 值

objective-c - 将点播视频从 IIS7 流式传输到 iOS 设备

objective-c - swift 3 - 方法不会覆盖其父类(super class)中的任何方法

swift - 如何限制用户文本输入并禁用 JSQMessagesViewController 中的发送按钮

ios - NSRegularExpression

iOS - 无法在具有比例变换的 UIViewAnimation 期间点击 UIView