My goal is to have a "narration" message in JSQMessagesViewController. I want this message to be centered on the screen. I am trying to center the message by centering it's message bubble container (contains the bubble and the text). This is my code for it:
class MessagesViewController: JSQMessagesViewController
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell
let message = messages[indexPath.row]
// Sent message
if message.senderId() == self.senderId {
// Normal outgoing message
}
// Narration Message
else if message.senderId() == Constants.lbSenderName {
cell.textView?.textAlignment = NSTextAlignment.Center
// new frame -- isn't changing the frame.
let newX = (cell.frame.width - (cell.messageBubbleContainerView?.frame.width)!)/2.0
cell.messageBubbleContainerView?.frame = CGRectMake(
newX,
(cell.messageBubbleContainerView?.frame.minY)!,
(cell.messageBubbleContainerView?.frame.width)!,
(cell.messageBubbleContainerView?.frame.height)!
)
}
// Received message
else {
// Normal incoming message
}
return cell
}
}
The cell does not move at all as I would expect it to. I have tried using
cell.messageBubbleContainerView?.translatesAutoresizingMaskIntoConstraints = true
but it makes the bubbles disappear. Any suggestion are appreciated, either to change the layout manually like I'm doing, or something I could use through JSQMessagesViewController.
I want it to look like this: Narration Messages