diff --git a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift index 3fdf8139..05ebc4b3 100644 --- a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift +++ b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift @@ -10,8 +10,9 @@ import UIKit class ChatLeftTextCell: ChatBaseCell { - @IBOutlet weak var bubbleBodyImageView: UIImageView! @IBOutlet weak var bubbleTailImageView: UIImageView! + + var bubbleBodyShapeLayer: CAShapeLayer! @IBOutlet weak var textContainerView: ChatTextContainerView! @IBOutlet weak var textContentTextView: ChatTextView! @@ -37,6 +38,10 @@ class ChatLeftTextCell: ChatBaseCell { UIView.performWithoutAnimation { [weak self] in self?.makeUI() } + + bubbleBodyShapeLayer = CAShapeLayer() + bubbleBodyShapeLayer.backgroundColor = UIColor.leftBubbleTintColor().CGColor + bubbleBodyShapeLayer.fillColor = UIColor.leftBubbleTintColor().CGColor textContentTextView.textContainer.lineFragmentPadding = 0 textContentTextView.font = UIFont.chatTextFont() @@ -52,8 +57,11 @@ class ChatLeftTextCell: ChatBaseCell { UIPasteboard.generalPasteboard().string = self?.textContentTextView.text } - bubbleBodyImageView.tintColor = UIColor.leftBubbleTintColor() bubbleTailImageView.tintColor = UIColor.leftBubbleTintColor() + + if let bubblePosition = layer.sublayers { + contentView.layer.insertSublayer(bubbleBodyShapeLayer, atIndex: UInt32(bubblePosition.count)) + } } @@ -102,7 +110,10 @@ class ChatLeftTextCell: ChatBaseCell { } strongSelf.textContainerView.frame = CGRect(x: CGRectGetMaxX(strongSelf.avatarImageView.frame) + YepConfig.chatCellGapBetweenTextContentLabelAndAvatar(), y: 3 + topOffset, width: textContentLabelWidth, height: strongSelf.bounds.height - topOffset - 3 * 2) - strongSelf.bubbleBodyImageView.frame = CGRectInset(strongSelf.textContainerView.frame, -12, -3) + + let bubbleBodyFrame = CGRectInset(strongSelf.textContainerView.frame, -12, -3) + + strongSelf.bubbleBodyShapeLayer.path = UIBezierPath(roundedRect: bubbleBodyFrame, cornerRadius: 30).CGPath if strongSelf.inGroup { strongSelf.nameLabel.text = strongSelf.user?.nickname @@ -110,7 +121,7 @@ class ChatLeftTextCell: ChatBaseCell { strongSelf.nameLabel.frame = CGRect(x: strongSelf.textContainerView.frame.origin.x, y: strongSelf.textContainerView.frame.origin.y - topOffset, width: strongSelf.nameLabel.frame.width, height: strongSelf.nameLabel.frame.height) } - strongSelf.bubbleTailImageView.center = CGPoint(x: CGRectGetMinX(strongSelf.bubbleBodyImageView.frame), y: CGRectGetMidY(strongSelf.avatarImageView.frame)) + strongSelf.bubbleTailImageView.center = CGPoint(x: CGRectGetMinX(bubbleBodyFrame), y: CGRectGetMidY(bubbleBodyFrame)) } diff --git a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.xib b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.xib index 155fccb3..6471ae3e 100644 --- a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.xib +++ b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.xib @@ -1,8 +1,8 @@ - + - + @@ -18,12 +18,6 @@ - - - - - - @@ -54,7 +48,6 @@ - @@ -63,7 +56,6 @@ - diff --git a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift index fa950987..c188f255 100644 --- a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift +++ b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift @@ -10,8 +10,9 @@ import UIKit class ChatRightTextCell: ChatRightBaseCell { - @IBOutlet weak var bubbleBodyImageView: UIImageView! @IBOutlet weak var bubbleTailImageView: UIImageView! + + var bubbleBodyShapeLayer: CAShapeLayer! @IBOutlet weak var textContainerView: ChatTextContainerView! @IBOutlet weak var textContentTextView: ChatTextView! @@ -34,6 +35,10 @@ class ChatRightTextCell: ChatRightBaseCell { UIView.performWithoutAnimation { [weak self] in self?.makeUI() } + + bubbleBodyShapeLayer = CAShapeLayer() + bubbleBodyShapeLayer.backgroundColor = UIColor.rightBubbleTintColor().CGColor + bubbleBodyShapeLayer.fillColor = UIColor.rightBubbleTintColor().CGColor textContentTextView.textContainer.lineFragmentPadding = 0 textContentTextView.font = UIFont.chatTextFont() @@ -54,12 +59,11 @@ class ChatRightTextCell: ChatRightBaseCell { self?.longPressAction?() } - bubbleBodyImageView.tintColor = UIColor.rightBubbleTintColor() bubbleTailImageView.tintColor = UIColor.rightBubbleTintColor() - - bubbleBodyImageView.userInteractionEnabled = true - let tap = UITapGestureRecognizer(target: self, action: "tapMediaView") - bubbleBodyImageView.addGestureRecognizer(tap) + + if let bubblePosition = layer.sublayers { + contentView.layer.insertSublayer(bubbleBodyShapeLayer, atIndex: UInt32(bubblePosition.count)) + } } func tapMediaView() { @@ -98,11 +102,15 @@ class ChatRightTextCell: ChatRightBaseCell { strongSelf.makeUI() strongSelf.textContainerView.frame = CGRect(x: CGRectGetMinX(strongSelf.avatarImageView.frame) - YepConfig.chatCellGapBetweenTextContentLabelAndAvatar() - textContentLabelWidth, y: 3, width: textContentLabelWidth, height: strongSelf.bounds.height - 3 * 2) - strongSelf.bubbleBodyImageView.frame = CGRectInset(strongSelf.textContainerView.frame, -12, -3) - - strongSelf.bubbleTailImageView.center = CGPoint(x: CGRectGetMaxX(strongSelf.bubbleBodyImageView.frame), y: CGRectGetMidY(strongSelf.avatarImageView.frame)) - strongSelf.dotImageView.center = CGPoint(x: CGRectGetMinX(strongSelf.bubbleBodyImageView.frame) - YepConfig.ChatCell.gapBetweenDotImageViewAndBubble, y: CGRectGetMidY(strongSelf.bubbleBodyImageView.frame)) + let bubbleBodyFrame = CGRectInset(strongSelf.textContainerView.frame, -12, -3) + + strongSelf.bubbleBodyShapeLayer.path = UIBezierPath(roundedRect: bubbleBodyFrame, cornerRadius: 30).CGPath +// strongSelf.bubbleBodyImageView.frame = + + strongSelf.bubbleTailImageView.center = CGPoint(x: CGRectGetMaxX(bubbleBodyFrame), y: CGRectGetMidY(strongSelf.avatarImageView.frame)) + + strongSelf.dotImageView.center = CGPoint(x: CGRectGetMinX(bubbleBodyFrame) - YepConfig.ChatCell.gapBetweenDotImageViewAndBubble, y: CGRectGetMidY(bubbleBodyFrame)) } } diff --git a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.xib b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.xib index e949beb3..b3b27867 100644 --- a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.xib +++ b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.xib @@ -1,8 +1,8 @@ - + - + @@ -18,11 +18,6 @@ - - - - - @@ -59,7 +54,6 @@ - @@ -69,7 +63,6 @@ -