JSQMessage在消息

时间:2016-02-05 17:38:20

标签: ios jsqmessagesviewcontroller

如何在bubblemessage中显示完整的图像。

我显示图像但是被剪切了:

see image

谢谢

2 个答案:

答案 0 :(得分:5)

我不相信有一个功能可以覆盖以获得所需的结果。但另一方面,如果你想分叉JSQMessageViewController并自己修改它。如果你去源项目,请转到mediaView开始的第74行的jSQMessages / JSQMessagesViewController / Model / JSQPhotoMediaItem.m

worldSizeZ

如果您将第78行if (self.cachedImageView == nil) { CGSize size = [self mediaViewDisplaySize]; UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image]; imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height); imageView.contentMode = UIViewContentModeScaleToFill; imageView.clipsToBounds = YES; [JSQMessagesMediaViewBubbleImageMasker applyBubbleImageMaskToMediaView:imageView isOutgoing:self.appliesMediaViewMaskAsOutgoing]; self.cachedImageView = imageView; } 更改为imageView.contentMode = UIViewContentModeScaleAspectFit; 如果你添加imageView.contentMode = UIViewContentModeScaleToFill;,你也会有泡泡形状。以下是之前和之后的一些屏幕截图。

Before Code Change

After Code Change

答案 1 :(得分:2)

确定 在这里我的代码:

override func viewDidLoad() {
        super.viewDidLoad()



    self.collectionView?.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero

    self.collectionView?.collectionViewLayout.incomingAvatarViewSize = CGSizeZero

    self.inputToolbar?.contentView?.rightBarButtonItemWidth = CGFloat(34.0)

    self.inputToolbar?.contentView?.rightBarButtonItem?.setTitle("Invia", forState: .Normal)

    self.inputToolbar?.contentView?.textView!.placeHolder = "messaggio.."

    setUpMessages()



    // Do any additional setup after loading the view.
}    


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return self.messages.count
}



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



    return self.messages[indexPath.item]
}

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

    let factory = JSQMessagesBubbleImageFactory()

    if messages[indexPath.row].senderId == senderId {
       return factory.outgoingMessagesBubbleImageWithColor(UIColor.lightGrayColor())
    } else {
       return factory.incomingMessagesBubbleImageWithColor(UIColor.greenColor())
    }

}



override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath)
    let message = self.messages[indexPath.row]

    return cell
}

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

    return nil
}

func setUpMessages() {

//load text messages:

    let mes1: JSQMessage = JSQMessage(senderId: "10", displayName: "io10", text: "Ciao")
    let mes2: JSQMessage = JSQMessage(senderId: "10", displayName: "io10", text: "Ciao2")
    let mes3: JSQMessage = JSQMessage(senderId: "10", displayName: "io10", text: "Ciao3")
    let mes4: JSQMessage = JSQMessage(senderId: "10", displayName: "io10", text: "Ciao4")

    messages.append(mes1)
    messages.append(mes2)
    messages.append(mes3)
    messages.append(mes4)

//load image message

   let img2 = JSQPhotoMediaItem(image: UIImage (named: "default"))

   let mes5 = JSQMessage(senderId: "10", senderDisplayName: "io10", media: img2)

    messages.append(mes5)        


}