我正在使用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
}
}
我应该改变一些东西,以便坚持到左边?
感谢
答案 0 :(得分:1)
我的错误。 您需要更改传入发件人的发件人ID。