2016-02-05 58 views

回答

5

我不相信有一個函數您可以重寫以獲得所需的結果。但另一方面,如果你想分叉JSQMessageViewController並自己修改它。如果你到源項目去jSQMessages/JSQMessagesViewController /型號/的mediaView下JSQPhotoMediaItem.m在線路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];你將有泡沫形狀也。以下是前後的一些屏幕截圖。

Before Code Change

After Code Change

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)   


} 
+0

正是我所需要的,我被捲入Ocj-C文檔和語法 – Sauron