Use cashapelayer to provent uiimageview size error

This commit is contained in:
kevinzhow
2015-11-03 07:46:31 +08:00
parent 52161eea4f
commit eebdf808e2
4 changed files with 37 additions and 33 deletions
@@ -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))
}
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -18,12 +18,6 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bubble_body" id="Yfx-Em-Job" userLabel="Bubble Body Image View">
<rect key="frame" x="63" y="0.0" width="116" height="129"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<color key="tintColor" white="0.84999999999999998" alpha="1" colorSpace="calibratedWhite"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="hYu-LI-zcX" userLabel="Avatar Image View">
<rect key="frame" x="15" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@@ -54,7 +48,6 @@
<size key="customSize" width="350" height="129"/>
<connections>
<outlet property="avatarImageView" destination="hYu-LI-zcX" id="X8N-rV-848"/>
<outlet property="bubbleBodyImageView" destination="Yfx-Em-Job" id="bQk-7x-1RF"/>
<outlet property="bubbleTailImageView" destination="ppr-iG-zxj" id="kxh-jI-4L8"/>
<outlet property="textContainerView" destination="Ieh-wh-12u" id="VVJ-yk-Twz"/>
<outlet property="textContentTextView" destination="o2v-vm-ItZ" id="lj4-7V-6TH"/>
@@ -63,7 +56,6 @@
</collectionViewCell>
</objects>
<resources>
<image name="bubble_body" width="42" height="40"/>
<image name="bubble_left_tail" width="13" height="14"/>
</resources>
</document>
@@ -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))
}
}
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -18,11 +18,6 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bubble_body" id="73l-kE-1KG" userLabel="Bubble Body Image View">
<rect key="frame" x="321" y="0.0" width="116" height="131"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="RKK-8d-9vO" userLabel="Avatar Image View">
<rect key="frame" x="445" y="0.0" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@@ -59,7 +54,6 @@
<size key="customSize" width="417" height="131"/>
<connections>
<outlet property="avatarImageView" destination="RKK-8d-9vO" id="Tsh-cB-lZt"/>
<outlet property="bubbleBodyImageView" destination="73l-kE-1KG" id="CiV-dM-4JT"/>
<outlet property="bubbleTailImageView" destination="1JC-jy-KNh" id="MGo-KB-Kb3"/>
<outlet property="dotImageView" destination="tB7-GG-3Zd" id="odg-hQ-nba"/>
<outlet property="textContainerView" destination="6da-H4-jC2" id="jNs-2X-eia"/>
@@ -69,7 +63,6 @@
</collectionViewCell>
</objects>
<resources>
<image name="bubble_body" width="42" height="40"/>
<image name="bubble_right_tail" width="13" height="14"/>
<image name="icon_dot_sending" width="10" height="10"/>
</resources>