Skip to content

Commit 46cb9ab

Browse files
committed
私信猴子表情特殊处理
1 parent ddbb281 commit 46cb9ab

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

Coding_iOS/Models/PrivateMessage.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef NS_ENUM(NSInteger, PrivateMessageSendStatus) {
2727
@property (strong, nonatomic) VoiceMedia *voiceMedia;
2828

2929
- (BOOL)hasMedia;
30+
- (BOOL)isSingleBigMonkey;
3031

3132
+ (instancetype)privateMessageWithObj:(id)obj andFriend:(User *)curFriend;
3233

Coding_iOS/Models/PrivateMessage.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ - (void)setContent:(NSString *)content{
3333
- (BOOL)hasMedia{
3434
return self.nextImg || (self.htmlMedia && self.htmlMedia.imageItems.count> 0);
3535
}
36-
36+
- (BOOL)isSingleBigMonkey{
37+
BOOL isSingleBigMonkey = NO;
38+
if (self.content.length == 0) {
39+
if (_htmlMedia.imageItems.count == 1) {
40+
HtmlMediaItem *item = [_htmlMedia.imageItems firstObject];
41+
if (item.type == HtmlMediaItemType_EmotionMonkey) {
42+
isSingleBigMonkey = YES;
43+
}
44+
}
45+
}
46+
return isSingleBigMonkey;
47+
}
3748
+ (instancetype)privateMessageWithObj:(id)obj andFriend:(User *)curFriend{
3849
PrivateMessage *nextMsg = [[PrivateMessage alloc] init];
3950
nextMsg.sender = [Login curLoginUser];

Coding_iOS/Views/CCell/MessageMediaItemCCell.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#define kCCellIdentifier_MessageMediaItem @"MessageMediaItemCCell"
10+
#define kCCellIdentifier_MessageMediaItem_Single @"MessageMediaItemCCell_Single"
1011

1112
#import <UIKit/UIKit.h>
1213
#import "HtmlMedia.h"
@@ -16,9 +17,11 @@
1617
@interface MessageMediaItemCCell : UICollectionViewCell
1718
@property (copy, nonatomic) void (^refreshMessageMediaCCellBlock)(CGFloat diff);
1819

19-
@property (strong, nonatomic) PrivateMessage *curPriMsg, *prePriMsg;
20+
//@property (strong, nonatomic) PrivateMessage *curPriMsg, *prePriMsg;
2021
@property (strong, nonatomic) NSObject *curObj;
2122
@property (strong, nonatomic) YLImageView *imgView;
2223

2324
+(CGSize)ccellSizeWithObj:(NSObject *)obj;
25+
+(CGSize)singleCcellSize;
26+
2427
@end

Coding_iOS/Views/CCell/MessageMediaItemCCell.m

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ - (void)setCurObj:(NSObject *)curObj{
6060
}
6161
}
6262
}];
63-
CGSize reSize = [[ImageSizeManager shareManager] sizeWithSrc:curMediaItem.src originalWidth:kMessageCell_ContentWidth maxHeight:kScreen_Height/2];
63+
64+
CGSize reSize = CGSizeZero;
65+
if ([self.reuseIdentifier isEqualToString:kCCellIdentifier_MessageMediaItem_Single]) {
66+
reSize = [MessageMediaItemCCell singleCcellSize];
67+
}else{
68+
reSize = [MessageMediaItemCCell ccellSizeWithObj:_curObj];
69+
}
6470
[_imgView setSize:reSize];
6571
}
6672
}
@@ -78,6 +84,10 @@ +(CGSize)ccellSizeWithObj:(NSObject *)obj{
7884
return itemSize;
7985
}
8086

87+
+(CGSize)singleCcellSize{
88+
return CGSizeMake(100, 100);
89+
}
90+
8191
- (void)layoutSubviews{
8292
[super layoutSubviews];
8393

Coding_iOS/Views/Cell/MessageCell.m

+23-19
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
7979
[self.mediaView setBackgroundView:nil];
8080
[self.mediaView setBackgroundColor:[UIColor clearColor]];
8181
[self.mediaView registerClass:[MessageMediaItemCCell class] forCellWithReuseIdentifier:kCCellIdentifier_MessageMediaItem];
82+
[self.mediaView registerClass:[MessageMediaItemCCell class] forCellWithReuseIdentifier:kCCellIdentifier_MessageMediaItem_Single];
8283
self.mediaView.dataSource = self;
8384
self.mediaView.delegate = self;
8485
[_bgImgView addSubview:self.mediaView];
@@ -173,7 +174,8 @@ - (void)setCurPriMsg:(PrivateMessage *)curPriMsg andPrePriMsg:(PrivateMessage *)
173174
// 有图片
174175
[_contentLabel setY:2*kMessageCell_PadingHeight + mediaViewHeight];
175176

176-
bgImgViewSize = CGSizeMake(kMessageCell_ContentWidth +2*kMessageCell_PadingWidth,
177+
CGFloat contentWidth = [_curPriMsg isSingleBigMonkey]? [MessageMediaItemCCell singleCcellSize].width : kMessageCell_ContentWidth;
178+
bgImgViewSize = CGSizeMake(contentWidth +2*kMessageCell_PadingWidth,
177179
mediaViewHeight +textSize.height + kMessageCell_PadingHeight*(_curPriMsg.content.length > 0? 3:2));
178180
} else if (curPriMsg.file || curPriMsg.voiceMedia) {
179181
bgImgViewSize = CGSizeMake(kMessageCell_ContentWidth, 40);
@@ -221,10 +223,6 @@ - (void)setCurPriMsg:(PrivateMessage *)curPriMsg andPrePriMsg:(PrivateMessage *)
221223
bgImg = [bgImg resizableImageWithCapInsets:UIEdgeInsetsMake(18, 30, bgImg.size.height - 19, bgImg.size.width - 31)];
222224
_contentLabel.textColor = [UIColor blackColor];
223225
_bgImgView.frame = bgImgViewFrame;
224-
if (_voiceView) {
225-
bgImg = nil; //使用bubbleView的背景
226-
_voiceView.type = BubbleTypeLeft;
227-
}
228226
}else{
229227
// 这是自己发的
230228
bgImgViewFrame = CGRectMake((kScreen_Width - kPaddingLeftWidth - kMessageCell_UserIconWith) -bgImgViewSize.width, curBottomY +kMessageCell_PadingHeight, bgImgViewSize.width, bgImgViewSize.height);
@@ -233,10 +231,10 @@ - (void)setCurPriMsg:(PrivateMessage *)curPriMsg andPrePriMsg:(PrivateMessage *)
233231
bgImg = [bgImg resizableImageWithCapInsets:UIEdgeInsetsMake(18, 30, bgImg.size.height - 19, bgImg.size.width - 31)];
234232
_contentLabel.textColor = [UIColor blackColor];
235233
_bgImgView.frame = bgImgViewFrame;
236-
if (_voiceView) {
237-
bgImg = nil; //使用bubbleView的背景
238-
_voiceView.type = BubbleTypeRight;
239-
}
234+
}
235+
if (_voiceView) {
236+
bgImg = nil; //使用bubbleView的背景
237+
_voiceView.type = BubbleTypeRight;
240238
}
241239

242240
__weak typeof(self) weakSelf = self;
@@ -248,7 +246,8 @@ - (void)setCurPriMsg:(PrivateMessage *)curPriMsg andPrePriMsg:(PrivateMessage *)
248246
[_bgImgView setImage:bgImg];
249247

250248
if (_mediaView) {
251-
[_mediaView setHeight:mediaViewHeight];
249+
CGFloat contentWidth = [_curPriMsg isSingleBigMonkey]? [MessageMediaItemCCell singleCcellSize].width : kMessageCell_ContentWidth;
250+
[_mediaView setSize:CGSizeMake(contentWidth, mediaViewHeight)];
252251
[_mediaView reloadData];
253252
}
254253

@@ -336,10 +335,14 @@ + (CGFloat)mediaViewHeightWithObj:(PrivateMessage *)curPriMsg{
336335
if (curPriMsg.nextImg) {
337336
mediaViewHeight += [MessageMediaItemCCell ccellSizeWithObj:curPriMsg.nextImg].height;
338337
}else{
339-
for (HtmlMediaItem *curItem in curPriMsg.htmlMedia.imageItems) {
340-
mediaViewHeight += [MessageMediaItemCCell ccellSizeWithObj:curItem].height +kMessageCell_PadingHeight;
338+
if ([curPriMsg isSingleBigMonkey]) {
339+
mediaViewHeight += [MessageMediaItemCCell singleCcellSize].height;
340+
}else{
341+
for (HtmlMediaItem *curItem in curPriMsg.htmlMedia.imageItems) {
342+
mediaViewHeight += [MessageMediaItemCCell ccellSizeWithObj:curItem].height +kMessageCell_PadingHeight;
343+
}
344+
mediaViewHeight -= kMessageCell_PadingHeight;
341345
}
342-
mediaViewHeight -= kMessageCell_PadingHeight;
343346
}
344347
}
345348
return mediaViewHeight;
@@ -356,10 +359,8 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
356359

357360
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
358361
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
359-
MessageMediaItemCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_MessageMediaItem forIndexPath:indexPath];
362+
MessageMediaItemCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:[_curPriMsg isSingleBigMonkey]? kCCellIdentifier_MessageMediaItem_Single: kCCellIdentifier_MessageMediaItem forIndexPath:indexPath];
360363
ccell.refreshMessageMediaCCellBlock = self.refreshMessageMediaCCellBlock;
361-
362-
ccell.curPriMsg = _curPriMsg;
363364
if (_curPriMsg.nextImg) {
364365
ccell.curObj = _curPriMsg.nextImg;
365366
}else{
@@ -370,14 +371,17 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
370371
return ccell;
371372
}
372373

373-
374374
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
375375
CGSize itemSize = CGSizeZero;
376376
if (_curPriMsg.nextImg) {
377377
itemSize = [MessageMediaItemCCell ccellSizeWithObj:_curPriMsg.nextImg];
378378
}else{
379-
HtmlMediaItem *curItem = [_curPriMsg.htmlMedia.imageItems objectAtIndex:indexPath.row];
380-
itemSize = [MessageMediaItemCCell ccellSizeWithObj:curItem];
379+
if ([_curPriMsg isSingleBigMonkey]) {
380+
itemSize = [MessageMediaItemCCell singleCcellSize];
381+
}else{
382+
HtmlMediaItem *curItem = [_curPriMsg.htmlMedia.imageItems objectAtIndex:indexPath.row];
383+
itemSize = [MessageMediaItemCCell ccellSizeWithObj:curItem];
384+
}
381385
}
382386
return itemSize;
383387
}

0 commit comments

Comments
 (0)