-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathTweetMediaItemSingleCCell.m
executable file
·98 lines (86 loc) · 3.63 KB
/
TweetMediaItemSingleCCell.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
98
//
// TweetMediaItemSingleCCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-9-5.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#define kTweetMediaItemCCellSingle_Width (0.6 *kScreen_Width)
#define kTweetMediaItemCCellSingle_WidthMonkey ((kScreen_Width - 36.0)/3.0)
#define kTweetMediaItemCCellSingle_MaxHeight (0.5 *kScreen_Height)
#import "TweetMediaItemSingleCCell.h"
#import "UIImageView+WebCache.h"
@implementation TweetMediaItemSingleCCell
@synthesize curMediaItem = _curMediaItem, imgView = _imgView, gifMarkView = _gifMarkView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)setCurMediaItem:(HtmlMediaItem *)curMediaItem{
if (!_imgView) {
_imgView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 0, kTweetMediaItemCCellSingle_Width, kTweetMediaItemCCellSingle_Width)];
_imgView.contentMode = UIViewContentModeScaleAspectFill;
_imgView.clipsToBounds = YES;
// _imgView.layer.masksToBounds = YES;
// _imgView.layer.cornerRadius = 2.0;
[self.contentView addSubview:_imgView];
}
if (_curMediaItem != curMediaItem) {
_curMediaItem = curMediaItem;
}
__weak typeof(self) weakSelf = self;
CGSize reSize;
if (curMediaItem.type == HtmlMediaItemType_EmotionMonkey) {
reSize = CGSizeMake(kTweetMediaItemCCellSingle_WidthMonkey, kTweetMediaItemCCellSingle_WidthMonkey);
}else{
reSize = [[ImageSizeManager shareManager] sizeWithSrc:_curMediaItem.src originalWidth:kTweetMediaItemCCellSingle_Width maxHeight:kTweetMediaItemCCellSingle_MaxHeight];
}
[_imgView sd_setImageWithURL:[_curMediaItem.src urlImageWithCodePathResize:2*reSize.width] placeholderImage:kPlaceholderCodingSquareWidth(150.0) options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image) {
if (![[ImageSizeManager shareManager] hasSrc:weakSelf.curMediaItem.src]) {
[[ImageSizeManager shareManager] saveImage:weakSelf.curMediaItem.src size:image.size];
if (weakSelf.refreshSingleCCellBlock) {
weakSelf.refreshSingleCCellBlock();
}
}
}
}];
[_imgView setSize:reSize];
// gifMark
if ([self.curMediaItem isGif]) {
if (!_gifMarkView) {
_gifMarkView = ({
UIImageView *imgView = [UIImageView new];
imgView.image = [UIImage imageNamed:@"gif_mark"];
[self.imgView addSubview:imgView];
@weakify(self);
[imgView mas_makeConstraints:^(MASConstraintMaker *make) {
@strongify(self);
make.size.mas_equalTo(CGSizeMake(24, 13));
make.right.bottom.equalTo(self.imgView).offset(0);
}];
imgView;
});
}
self.gifMarkView.hidden = NO;
}else{
self.gifMarkView.hidden = YES;
}
}
+(CGSize)ccellSizeWithObj:(id)obj{
CGSize itemSize = CGSizeZero;
if ([obj isKindOfClass:[HtmlMediaItem class]]) {
HtmlMediaItem *curMediaItem = (HtmlMediaItem *)obj;
if (curMediaItem.type == HtmlMediaItemType_EmotionMonkey) {
itemSize = CGSizeMake(kTweetMediaItemCCellSingle_WidthMonkey, kTweetMediaItemCCellSingle_WidthMonkey);
}else{
itemSize = [[ImageSizeManager shareManager] sizeWithSrc:curMediaItem.src originalWidth:kTweetMediaItemCCellSingle_Width maxHeight:kTweetMediaItemCCellSingle_MaxHeight];
}
}
return itemSize;
}
@end