66// Copyright (c) 2014年 Coding. All rights reserved.
77//
88
9- // #define kTweetCell_PadingLeft 50.0
10- // #define kTweetCell_PadingTop 45.0
11-
129#define kTweetCell_PadingLeft kPaddingLeftWidth
13- #define kTweetCell_PadingTop (55 + 20 )
10+ #define kTweetCell_PadingTop (60 + 15 )
1411
1512#define kTweetCell_PadingBottom 10.0
1613#define kTweetCell_ContentWidth (kScreen_Width -kTweetCell_PadingLeft - kPaddingLeftWidth )
3532#import " UICustomCollectionView.h"
3633
3734@interface TweetCell ()
35+ @property (strong , nonatomic ) Tweet *tweet;
36+ @property (assign , nonatomic ) BOOL needTopView;
3837
38+ @property (strong , nonatomic ) UIView *topView;
3939@property (strong , nonatomic ) UITapImageView *ownerImgView;
4040@property (strong , nonatomic ) UIButton *ownerNameBtn;
4141@property (strong , nonatomic ) UITTTAttributedLabel *contentLabel;
@@ -46,20 +46,13 @@ @interface TweetCell ()
4646@property (strong , nonatomic ) UICollectionView *likeUsersView;
4747@property (strong , nonatomic ) UITableView *commentListView;
4848@property (strong , nonatomic ) UIImageView *timeClockIconView, *commentOrLikeBeginImgView, *commentOrLikeSplitlineView;
49- @property (strong , nonatomic ) NSMutableDictionary *imageViewsDict;
5049@end
5150
5251@implementation TweetCell
5352
54- - (void )setTweet : (Tweet *)tweet {
55- if (_tweet != tweet) {
56- _tweet = tweet;
57- }
58- if (_imageViewsDict) {
59- [_imageViewsDict removeAllObjects ];
60- }else {
61- _imageViewsDict = [[NSMutableDictionary alloc ] init ];
62- }
53+ - (void )setTweet : (Tweet *)tweet needTopView : (BOOL )needTopView {
54+ _tweet = tweet;
55+ _needTopView = needTopView;
6356}
6457
6558- (id )initWithStyle : (UITableViewCellStyle)style reuseIdentifier : (NSString *)reuseIdentifier
@@ -70,28 +63,30 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
7063 self.selectionStyle = UITableViewCellSelectionStyleNone;
7164 self.backgroundColor = [UIColor clearColor ];
7265// self.backgroundColor = [UIColor colorWithHexString:@"0xf3f3f3"];
73- UIView *topView = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width , 15 )];
74- topView.backgroundColor = [UIColor colorWithHexString: @" 0xeeeeee" ];
75- [self .contentView addSubview: topView];
66+ if (!_topView) {
67+ _topView = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , kScreen_Width , 15 )];
68+ _topView.backgroundColor = [UIColor colorWithHexString: @" 0xeeeeee" ];
69+ [self .contentView addSubview: _topView];
70+ }
7671
7772 if (!self.ownerImgView ) {
78- self.ownerImgView = [[UITapImageView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 15 + CGRectGetMaxY (topView .frame), 33 , 33 )];
73+ self.ownerImgView = [[UITapImageView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 15 + CGRectGetMaxY (_topView .frame), 33 , 33 )];
7974 [self .ownerImgView doCircleFrame ];
8075 [self .contentView addSubview: self .ownerImgView];
8176 }
8277 if (!self.ownerNameBtn ) {
8378 self.ownerNameBtn = [UIButton buttonWithUserStyle ];
84- self.ownerNameBtn .frame = CGRectMake (CGRectGetMaxX (self.ownerImgView .frame ) + 10 , 23 + CGRectGetMaxY (topView .frame ), 50 , 20 );
79+ self.ownerNameBtn .frame = CGRectMake (CGRectGetMaxX (self.ownerImgView .frame ) + 10 , 23 + CGRectGetMaxY (_topView .frame ), 50 , 20 );
8580 [self .ownerNameBtn addTarget: self action: @selector (userBtnClicked ) forControlEvents: UIControlEventTouchUpInside];
8681 [self .contentView addSubview: self .ownerNameBtn];
8782 }
8883 if (!self.timeClockIconView ) {
89- self.timeClockIconView = [[UIImageView alloc ] initWithFrame: CGRectMake (kScreen_Width - kPaddingLeftWidth - 70 , 25 + CGRectGetMaxY (topView .frame), 12 , 12 )];
84+ self.timeClockIconView = [[UIImageView alloc ] initWithFrame: CGRectMake (kScreen_Width - kPaddingLeftWidth - 70 , 25 + CGRectGetMaxY (_topView .frame), 12 , 12 )];
9085 self.timeClockIconView .image = [UIImage imageNamed: @" time_clock_icon" ];
9186 [self .contentView addSubview: self .timeClockIconView];
9287 }
9388 if (!self.timeLabel ) {
94- self.timeLabel = [[UILabel alloc ] initWithFrame: CGRectMake (kScreen_Width - kPaddingLeftWidth - 55 , 23 + CGRectGetMaxY (topView .frame), 55 , 12 )];
89+ self.timeLabel = [[UILabel alloc ] initWithFrame: CGRectMake (kScreen_Width - kPaddingLeftWidth - 55 , 23 + CGRectGetMaxY (_topView .frame), 55 , 12 )];
9590 self.timeLabel .font = kTweet_TimtFont ;
9691 self.timeLabel .textAlignment = NSTextAlignmentRight;
9792 self.timeLabel .textColor = [UIColor colorWithHexString: @" 0x999999" ];
@@ -228,6 +223,7 @@ - (void)layoutSubviews{
228223 if (!_tweet) {
229224 return ;
230225 }
226+ self.topView .hidden = !_needTopView;
231227 // owner头像
232228 __weak __typeof (self)weakSelf = self;
233229 [self .ownerImgView setImageWithUrl: [_tweet.owner.avatar urlImageWithCodePathResizeToView: _ownerImgView] placeholderImage: kPlaceholderMonkeyRoundView (_ownerImgView) tapBlock: ^(id obj) {
@@ -242,18 +238,30 @@ - (void)layoutSubviews{
242238 [self .timeClockIconView setX: timeLabelX-15 ];
243239
244240
241+ CGFloat centerY = 15 + 15 + 33.0 /2 ;
242+ CGFloat curBottomY = _needTopView? 0 : -15 ;
243+ centerY += curBottomY;
244+
245+ [self .topView setY: curBottomY];
246+ [self .ownerImgView setCenterY: centerY];
247+ [self .ownerNameBtn setCenterY: centerY];
248+ [self .timeClockIconView setCenterY: centerY];
249+ [self .timeLabel setCenterY: centerY];
250+
251+ curBottomY += kTweetCell_PadingTop ;
245252
246253 // owner冒泡text内容
247254// [self.contentLabel setWidth:kTweetCell_ContentWidth];
248255// self.contentLabel.text = _tweet.content;
249256// [self.contentLabel sizeToFit];
257+ [self .contentLabel setY: curBottomY];
250258 [self .contentLabel setLongString: _tweet.content withFitWidth: kTweetCell_ContentWidth maxHeight: kTweet_ContentMaxHeight ];
251259 for (HtmlMediaItem *item in _tweet.htmlMedia .mediaItems ) {
252260 if (item.displayStr .length > 0 && !(item.type == HtmlMediaItemType_Code ||item.type == HtmlMediaItemType_EmotionEmoji)) {
253261 [self .contentLabel addLinkToTransitInformation: [NSDictionary dictionaryWithObject: item forKey: @" value" ] withRange: item.range];
254262 }
255263 }
256- CGFloat curBottomY = kTweetCell_PadingTop + [TweetCell contentLabelHeightWithTweet: _tweet];
264+ curBottomY += [TweetCell contentLabelHeightWithTweet: _tweet];
257265 // 图片缩略图展示
258266 if (_tweet.htmlMedia .imageItems .count > 0 ) {
259267
@@ -348,10 +356,11 @@ - (void)layoutSubviews{
348356 }
349357}
350358
351- + (CGFloat)cellHeightWithObj : (id )obj {
359+ + (CGFloat)cellHeightWithObj : (id )obj needTopView : ( BOOL ) needTopView {
352360 Tweet *tweet = (Tweet *)obj;
353361 CGFloat cellHeight = 0 ;
354- cellHeight += kTweetCell_PadingTop ;
362+ cellHeight += needTopView? 0 : -15 ;
363+ cellHeight += kTweetCell_PadingTop ;
355364 cellHeight += [self contentLabelHeightWithTweet: tweet];
356365 cellHeight += [self contentMediaHeightWithTweet: tweet];
357366 cellHeight += [self locationHeightWithTweet: tweet];
@@ -458,12 +467,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
458467 _refreshSingleCCellBlock ();
459468 }
460469 };
461- [_imageViewsDict setObject: ccell.imgView forKey: indexPath];
462470 return ccell;
463471 }else {
464472 TweetMediaItemCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier: kCCellIdentifier_TweetMediaItem forIndexPath: indexPath];
465473 ccell.curMediaItem = curMediaItem;
466- [_imageViewsDict setObject: ccell.imgView forKey: indexPath];
467474 return ccell;
468475 }
469476 }else {
@@ -530,7 +537,6 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
530537 HtmlMediaItem *imageItem = [_tweet.htmlMedia.imageItems objectAtIndex: i];
531538 MJPhoto *photo = [[MJPhoto alloc ] init ];
532539 photo.url = [NSURL URLWithString: imageItem.src]; // 图片路径
533- photo.srcImageView = [_imageViewsDict objectForKey: [NSIndexPath indexPathForItem: i inSection: 0 ]]; // 来源于哪个UIImageView
534540 [photos addObject: photo];
535541 }
536542
0 commit comments