Skip to content

Commit 3be45be

Browse files
committed
【朋友圈、热门冒泡】第一个冒泡的灰边去掉
1 parent 1871ab0 commit 3be45be

5 files changed

Lines changed: 44 additions & 39 deletions

File tree

Coding_iOS/Controllers/RootControllers/Tweet_RootViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
407407
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
408408
TweetCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Tweet forIndexPath:indexPath];
409409
Tweets *curTweets = [self getCurTweets];
410-
cell.tweet = [curTweets.list objectAtIndex:indexPath.row];
410+
[cell setTweet:[curTweets.list objectAtIndex:indexPath.row] needTopView:(_curIndex == Tweet_RootViewControllerTypeAll || indexPath.row != 0)];
411411
cell.outTweetsIndex = _curIndex;
412412

413413
__weak typeof(self) weakSelf = self;
@@ -496,7 +496,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
496496

497497
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
498498
Tweets *curTweets = [self getCurTweets];
499-
return [TweetCell cellHeightWithObj:[curTweets.list objectAtIndex:indexPath.row]];
499+
return [TweetCell cellHeightWithObj:[curTweets.list objectAtIndex:indexPath.row] needTopView:(_curIndex == Tweet_RootViewControllerTypeAll || indexPath.row != 0)];
500500
}
501501

502502
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

Coding_iOS/Controllers/Topic/CSTopicDetailVC.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
155155
}
156156

157157
TweetCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Tweet forIndexPath:indexPath];
158-
159158
if (indexPath.section == 0) {
160-
cell.tweet = _curTopWteet;
159+
[cell setTweet:_curTopWteet needTopView:NO];
161160
}else{
162-
cell.tweet = [_curTweets.list objectAtIndex:indexPath.row];
161+
[cell setTweet:[_curTweets.list objectAtIndex:indexPath.row] needTopView:YES];
163162
}
164163

165164
cell.outTweetsIndex = _curIndex;
@@ -259,14 +258,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
259258
if (_curTopWteet && indexPath.row ==0) {
260259
return 36;
261260
}else if(_curTopWteet && indexPath.row == 1){
262-
return [TweetCell cellHeightWithObj:_curTopWteet];
261+
return [TweetCell cellHeightWithObj:_curTopWteet needTopView:NO];
263262
}
264263
else {
265264
return 0;
266265
}
267266
}
268-
269-
return [TweetCell cellHeightWithObj:[_curTweets.list objectAtIndex:indexPath.row]];
267+
return [TweetCell cellHeightWithObj:[_curTweets.list objectAtIndex:indexPath.row] needTopView:YES];
270268
}
271269

272270
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

Coding_iOS/Controllers/UserTweetsViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
224224

225225
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
226226
TweetCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Tweet forIndexPath:indexPath];
227-
cell.tweet = [_curTweets.list objectAtIndex:indexPath.row];
227+
[cell setTweet:[_curTweets.list objectAtIndex:indexPath.row] needTopView:(indexPath.row != 0)];
228228

229229
__weak typeof(self) weakSelf = self;
230230
cell.commentClickedBlock = ^(Tweet *tweet, NSInteger index, id sender){
@@ -299,7 +299,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
299299
}
300300

301301
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
302-
return [TweetCell cellHeightWithObj:[_curTweets.list objectAtIndex:indexPath.row]];
302+
return [TweetCell cellHeightWithObj:[_curTweets.list objectAtIndex:indexPath.row] needTopView:(indexPath.row != 0)];
303303
}
304304

305305
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

Coding_iOS/Views/Cell/TweetCell.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ typedef void (^MoreLikersBtnClickedBlock) (Tweet *curTweet);
2020
typedef void (^LocationClickedBlock) (Tweet *curTweet);
2121

2222
@interface TweetCell : UITableViewCell <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, TTTAttributedLabelDelegate>
23-
@property (strong, nonatomic) Tweet *tweet;
2423
@property (nonatomic, assign) NSInteger outTweetsIndex;
2524

25+
- (void)setTweet:(Tweet *)tweet needTopView:(BOOL)needTopView;
26+
2627
@property (nonatomic, copy) CommentClickedBlock commentClickedBlock;
2728
@property (nonatomic, copy) LikeBtnClickedBlock likeBtnClickedBlock;
2829
@property (nonatomic, copy) UserBtnClickedBlock userBtnClickedBlock;
@@ -36,5 +37,5 @@ typedef void (^LocationClickedBlock) (Tweet *curTweet);
3637

3738
typedef void (^MoreLikersBtnClickedBlock) (Tweet *curTweet);
3839

39-
+ (CGFloat)cellHeightWithObj:(id)obj;;
40+
+ (CGFloat)cellHeightWithObj:(id)obj needTopView:(BOOL)needTopView;
4041
@end

Coding_iOS/Views/Cell/TweetCell.m

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
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)
@@ -35,7 +32,10 @@
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

Comments
 (0)