1

我正在将 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
}

}

我应该改变一些东西让它坚持到左边吗?

谢谢

4

1 回答 1

1

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

于 2015-01-29T14:51:05.833 回答