-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMessageMediaItemCCell.m
executable file
·97 lines (84 loc) · 3.83 KB
/
MessageMediaItemCCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// MessageMediaItemCCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-9-17.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "MessageMediaItemCCell.h"
#define kMessageCell_ContentWidth (0.6 *kScreen_Width)
@implementation MessageMediaItemCCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)setCurObj:(NSObject *)curObj{
_curObj = curObj;
if (!_curObj) {
return;
}
if (!_imgView) {
_imgView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 0, kMessageCell_ContentWidth, kMessageCell_ContentWidth)];
_imgView.contentMode = UIViewContentModeScaleAspectFill;
_imgView.clipsToBounds = YES;
_imgView.layer.masksToBounds = YES;
_imgView.layer.cornerRadius = 6.0;
// [_imgView doBorderWidth:0.5 color:nil cornerRadius:5.0];
[self.contentView addSubview:_imgView];
}
if ([_curObj isKindOfClass:[UIImage class]]) {
UIImage *curImage = (UIImage *)_curObj;
self.imgView.image = curImage;
[_imgView setSize:[[ImageSizeManager shareManager] sizeWithImage:curImage originalWidth:kMessageCell_ContentWidth maxHeight:kScreen_Height/2]];
}else if ([_curObj isKindOfClass:[HtmlMediaItem class]]){
HtmlMediaItem *curMediaItem = (HtmlMediaItem *)_curObj;
NSURL *currentImageURL = [curMediaItem.src urlImageWithCodePathResizeToView:_imgView];
__weak typeof(self) weakSelf = self;
[self.imgView sd_setImageWithURL:currentImageURL placeholderImage:kPlaceholderCodingSquareWidth(150.0) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if ([weakSelf.curObj isKindOfClass:[HtmlMediaItem class]]) {
HtmlMediaItem *curBlockMediaItem = (HtmlMediaItem *)weakSelf.curObj;
if (image && [imageURL.absoluteString isEqualToString:currentImageURL.absoluteString]) {
CGSize imageSize = image.size;
if (![[ImageSizeManager shareManager] hasSrc:curBlockMediaItem.src]) {
[[ImageSizeManager shareManager] saveImage:curBlockMediaItem.src size:imageSize];
CGSize reSize = [[ImageSizeManager shareManager] sizeWithImage:image originalWidth:kMessageCell_ContentWidth maxHeight:kScreen_Height/2];
if (weakSelf.refreshMessageMediaCCellBlock) {
weakSelf.refreshMessageMediaCCellBlock(reSize.height - kMessageCell_ContentWidth);
}
}
}
}
}];
CGSize reSize = CGSizeZero;
if ([self.reuseIdentifier isEqualToString:kCCellIdentifier_MessageMediaItem_Single]) {
reSize = [MessageMediaItemCCell monkeyCcellSize];
}else{
reSize = [MessageMediaItemCCell ccellSizeWithObj:_curObj];
}
[_imgView setSize:reSize];
}
}
+(CGSize)ccellSizeWithObj:(NSObject *)obj{
CGSize itemSize = CGSizeZero;
if ([obj isKindOfClass:[UIImage class]]) {
itemSize = [[ImageSizeManager shareManager] sizeWithImage:(UIImage *)obj originalWidth:kMessageCell_ContentWidth maxHeight:kScreen_Height/2];
}else if ([obj isKindOfClass:[VoiceMedia class]]) {
itemSize = CGSizeMake(kMessageCell_ContentWidth, 40);
}else if ([obj isKindOfClass:[HtmlMediaItem class]]){
HtmlMediaItem *curMediaItem = (HtmlMediaItem *)obj;
itemSize = [[ImageSizeManager shareManager] sizeWithSrc:curMediaItem.src originalWidth:kMessageCell_ContentWidth maxHeight:kScreen_Height/2];
}
return itemSize;
}
+(CGSize)monkeyCcellSize{
CGFloat width = kScaleFrom_iPhone5_Desgin(100);
return CGSizeMake(width, width);
}
- (void)layoutSubviews{
[super layoutSubviews];
}
@end