Skip to content

Commit 22c91d6

Browse files
author
Nicola Giancecchi
committed
modifiche
1 parent 2b26ea5 commit 22c91d6

File tree

9 files changed

+597
-513
lines changed

9 files changed

+597
-513
lines changed

JSQMessagesViewController/Model/JSQPhotoMediaItem.m

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ - (UIView *)mediaView
7979

8080
if (self.cachedImageView == nil) {
8181
CGSize size = [self mediaViewDisplaySize];
82-
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image];
82+
UIImage *image = [self fixOrientation:self.image];
83+
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
8384
imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
8485
imageView.contentMode = UIViewContentModeScaleAspectFill;
8586
imageView.clipsToBounds = YES;
@@ -90,6 +91,86 @@ - (UIView *)mediaView
9091
return self.cachedImageView;
9192
}
9293

94+
- (UIImage *)fixOrientation:(UIImage*)image {
95+
96+
// No-op if the orientation is already correct
97+
if (image.imageOrientation == UIImageOrientationUp) return image;
98+
99+
// We need to calculate the proper transformation to make the image upright.
100+
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
101+
CGAffineTransform transform = CGAffineTransformIdentity;
102+
103+
switch (image.imageOrientation) {
104+
case UIImageOrientationDown:
105+
case UIImageOrientationDownMirrored:
106+
transform = CGAffineTransformTranslate(transform, image.size.width, image.size.height);
107+
transform = CGAffineTransformRotate(transform, M_PI);
108+
break;
109+
110+
case UIImageOrientationLeft:
111+
case UIImageOrientationLeftMirrored:
112+
transform = CGAffineTransformTranslate(transform, image.size.width, 0);
113+
transform = CGAffineTransformRotate(transform, M_PI_2);
114+
break;
115+
116+
case UIImageOrientationRight:
117+
case UIImageOrientationRightMirrored:
118+
transform = CGAffineTransformTranslate(transform, 0, image.size.height);
119+
transform = CGAffineTransformRotate(transform, -M_PI_2);
120+
break;
121+
case UIImageOrientationUp:
122+
case UIImageOrientationUpMirrored:
123+
break;
124+
}
125+
126+
switch (image.imageOrientation) {
127+
case UIImageOrientationUpMirrored:
128+
case UIImageOrientationDownMirrored:
129+
transform = CGAffineTransformTranslate(transform, image.size.width, 0);
130+
transform = CGAffineTransformScale(transform, -1, 1);
131+
break;
132+
133+
case UIImageOrientationLeftMirrored:
134+
case UIImageOrientationRightMirrored:
135+
transform = CGAffineTransformTranslate(transform, image.size.height, 0);
136+
transform = CGAffineTransformScale(transform, -1, 1);
137+
break;
138+
case UIImageOrientationUp:
139+
case UIImageOrientationDown:
140+
case UIImageOrientationLeft:
141+
case UIImageOrientationRight:
142+
break;
143+
}
144+
145+
// Now we draw the underlying CGImage into a new context, applying the transform
146+
// calculated above.
147+
CGContextRef ctx = CGBitmapContextCreate(NULL, image.size.width, image.size.height,
148+
CGImageGetBitsPerComponent(image.CGImage), 0,
149+
CGImageGetColorSpace(image.CGImage),
150+
CGImageGetBitmapInfo(image.CGImage));
151+
CGContextConcatCTM(ctx, transform);
152+
switch (image.imageOrientation) {
153+
case UIImageOrientationLeft:
154+
case UIImageOrientationLeftMirrored:
155+
case UIImageOrientationRight:
156+
case UIImageOrientationRightMirrored:
157+
// Grr...
158+
CGContextDrawImage(ctx, CGRectMake(0,0,image.size.height,image.size.width), image.CGImage);
159+
break;
160+
161+
default:
162+
CGContextDrawImage(ctx, CGRectMake(0,0,image.size.width,image.size.height), image.CGImage);
163+
break;
164+
}
165+
166+
// And now we just create a new UIImage from the drawing context
167+
CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
168+
UIImage *img = [UIImage imageWithCGImage:cgimg];
169+
CGContextRelease(ctx);
170+
CGImageRelease(cgimg);
171+
return img;
172+
}
173+
93174
- (NSUInteger)mediaHash
94175
{
95176
return self.hash;

JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ - (void)awakeFromNib
125125
self.messageBubbleTopLabel.textColor = [UIColor lightGrayColor];
126126

127127
self.cellBottomLabel.font = [UIFont systemFontOfSize:11.0f];
128-
self.cellBottomLabel.textColor = [UIColor lightGrayColor];
128+
self.cellBottomLabel.textColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];
129129

130130
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jsq_handleTapGesture:)];
131131
[self addGestureRecognizer:tap];

JSQMessagesViewController/Views/JSQMessagesCollectionViewCellIncoming.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<nil key="highlightedColor"/>
8080
</label>
8181
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="cell bottom label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UPz-5x-c1T" userLabel="Cell bottom label" customClass="JSQMessagesLabel">
82-
<rect key="frame" x="36" y="134" width="284" height="20"/>
82+
<rect key="frame" x="48" y="134" width="272" height="20"/>
8383
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
8484
<constraints>
8585
<constraint firstAttribute="height" constant="20" id="xPR-Ph-Ze9"/>
@@ -93,9 +93,9 @@
9393
</view>
9494
<constraints>
9595
<constraint firstAttribute="bottom" secondItem="btS-p8-B7Z" secondAttribute="bottom" constant="20" id="16P-yZ-OVg"/>
96-
<constraint firstItem="UPz-5x-c1T" firstAttribute="leading" secondItem="btS-p8-B7Z" secondAttribute="leading" id="7BQ-qA-S0x"/>
9796
<constraint firstItem="Ufa-bF-l1Y" firstAttribute="leading" secondItem="btS-p8-B7Z" secondAttribute="leading" id="85j-cC-NZz"/>
9897
<constraint firstAttribute="bottom" secondItem="UPz-5x-c1T" secondAttribute="bottom" id="CCF-fJ-vmj"/>
98+
<constraint firstItem="btS-p8-B7Z" firstAttribute="leading" secondItem="UPz-5x-c1T" secondAttribute="leading" constant="-12" id="DZa-h1-djb"/>
9999
<constraint firstItem="Ufa-bF-l1Y" firstAttribute="top" secondItem="afj-rd-iNv" secondAttribute="bottom" id="Gwd-Z1-a8K"/>
100100
<constraint firstAttribute="bottom" secondItem="Da1-09-wR4" secondAttribute="bottom" constant="20" id="HLG-aN-h91"/>
101101
<constraint firstItem="UPz-5x-c1T" firstAttribute="top" secondItem="btS-p8-B7Z" secondAttribute="bottom" id="KXM-gt-Za5"/>
@@ -126,7 +126,7 @@
126126
<outlet property="textViewAvatarHorizontalSpaceConstraint" destination="j0I-pm-eex" id="ns4-3c-A7B"/>
127127
<outlet property="textViewMarginHorizontalSpaceConstraint" destination="GSY-Qb-8cR" id="YpC-ig-o9H"/>
128128
</connections>
129-
<point key="canvasLocation" x="89" y="299"/>
129+
<point key="canvasLocation" x="-11" y="226"/>
130130
</collectionViewCell>
131131
</objects>
132132
<simulatedMetricsContainer key="defaultSimulatedMetrics">

JSQMessagesViewController/Views/JSQMessagesCollectionViewCellOutgoing.xib

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<nil key="highlightedColor"/>
8383
</label>
8484
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="cell bottom label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7Uc-dI-YDD" userLabel="Cell bottom label" customClass="JSQMessagesLabel">
85-
<rect key="frame" x="0.0" y="134" width="256" height="20"/>
85+
<rect key="frame" x="0.0" y="134" width="254" height="20"/>
8686
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
8787
<constraints>
8888
<constraint firstAttribute="height" constant="20" id="cPs-M4-tjX"/>
@@ -92,7 +92,7 @@
9292
<nil key="highlightedColor"/>
9393
</label>
9494
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icona_spunta.png" translatesAutoresizingMaskIntoConstraints="NO" id="IGP-Jg-EkF">
95-
<rect key="frame" x="264" y="134" width="20" height="20"/>
95+
<rect key="frame" x="254" y="134" width="20" height="20"/>
9696
<constraints>
9797
<constraint firstAttribute="width" constant="20" id="3I8-d7-RYd"/>
9898
<constraint firstAttribute="height" constant="20" id="jCH-eC-gzd"/>
@@ -102,16 +102,15 @@
102102
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
103103
</view>
104104
<constraints>
105+
<constraint firstItem="IGP-Jg-EkF" firstAttribute="trailing" secondItem="2zh-vR-QJW" secondAttribute="trailing" constant="-10" id="3eJ-dI-oRq"/>
105106
<constraint firstItem="IGP-Jg-EkF" firstAttribute="top" secondItem="2zh-vR-QJW" secondAttribute="bottom" id="4nA-Qm-pNd"/>
106107
<constraint firstItem="p52-YN-yLu" firstAttribute="top" secondItem="jxM-YD-sVG" secondAttribute="bottom" id="98K-Do-9fQ"/>
107108
<constraint firstAttribute="trailing" secondItem="jxM-YD-sVG" secondAttribute="trailing" id="AwY-g7-f1T"/>
108-
<constraint firstItem="2zh-vR-QJW" firstAttribute="trailing" secondItem="IGP-Jg-EkF" secondAttribute="trailing" id="BRy-Tk-1o4"/>
109109
<constraint firstAttribute="bottom" secondItem="2zh-vR-QJW" secondAttribute="bottom" constant="20" id="EEY-BQ-88U"/>
110110
<constraint firstItem="jxM-YD-sVG" firstAttribute="top" secondItem="23f-xH-rkY" secondAttribute="top" id="HYT-Tw-whz"/>
111111
<constraint firstAttribute="trailing" secondItem="X89-B1-aAd" secondAttribute="trailing" id="KLt-Ix-wDa"/>
112-
<constraint firstItem="IGP-Jg-EkF" firstAttribute="leading" secondItem="7Uc-dI-YDD" secondAttribute="trailing" constant="8" id="MZa-69-JjB"/>
112+
<constraint firstItem="IGP-Jg-EkF" firstAttribute="leading" secondItem="7Uc-dI-YDD" secondAttribute="trailing" id="MZa-69-JjB"/>
113113
<constraint firstItem="X89-B1-aAd" firstAttribute="leading" secondItem="2zh-vR-QJW" secondAttribute="trailing" constant="2" id="Une-yZ-FwB"/>
114-
<constraint firstItem="X89-B1-aAd" firstAttribute="top" secondItem="jxM-YD-sVG" secondAttribute="bottom" constant="80" id="V0T-0e-BOK"/>
115114
<constraint firstItem="7Uc-dI-YDD" firstAttribute="top" secondItem="2zh-vR-QJW" secondAttribute="bottom" id="boN-uu-y51"/>
116115
<constraint firstAttribute="bottom" secondItem="IGP-Jg-EkF" secondAttribute="bottom" id="nV9-7w-bJ6"/>
117116
<constraint firstAttribute="bottom" secondItem="7Uc-dI-YDD" secondAttribute="bottom" id="oXV-La-hoH"/>
@@ -140,7 +139,7 @@
140139
<outlet property="textViewAvatarHorizontalSpaceConstraint" destination="Une-yZ-FwB" id="YAc-9n-1vJ"/>
141140
<outlet property="textViewMarginHorizontalSpaceConstraint" destination="y4J-ls-ATQ" id="AJD-Vf-pc8"/>
142141
</connections>
143-
<point key="canvasLocation" x="212" y="355"/>
142+
<point key="canvasLocation" x="-86" y="190"/>
144143
</collectionViewCell>
145144
</objects>
146145
<resources>

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ SPEC CHECKSUMS:
1010
JSQSystemSoundPlayer: c5850e77a4363ffd374cd851154b9af93264ed8d
1111
OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92
1212

13-
COCOAPODS: 0.38.0
13+
COCOAPODS: 0.38.2

Pods/Manifest.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)