2

如何在气泡消息中显示完整图像。

我显示了图像,但它被剪切了:

看图片

谢谢你

4

2 回答 2

5

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

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;
}

如果您将第 78 行更改imageView.contentMode = UIViewContentModeScaleAspectFit;imageView.contentMode = UIViewContentModeScaleToFill; 添加imageView.backgroundColor = [UIColor lightGrayColor];,您也会有气泡形状。这是之前和之后的一些屏幕截图。

代码更改前

代码更改后

于 2016-02-08T02:40:36.350 回答
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)        


}
于 2016-02-06T14:03:06.647 回答