仿微信朋友圈以及新浪微博

難點:由于有視頻,語音搅幅,地理位置阅束,文字,圖片等不同的數(shù)據(jù)類型茄唐,所以相對來說布局叫復(fù)雜

主要的思路是:在獲取數(shù)據(jù)的同時息裸,計算好每個cell的布局,高度

1.數(shù)據(jù)類

@interface ShareInfoDemo : NSObject

@property(nonatomic,strong)NSString *idNum;

@property(nonatomic,strong)NSString *type;

@property(nonatomic,strong)NSString *content;

@property(nonatomic,strong)NSArray? *referUris;

@property(nonatomic,strong)NSString *duration;

@property(nonatomic,strong)NSString *sendTime;

@property(nonatomic,strong)SelfDataModel *user;

@property(nonatomic,strong)NSMutableDictionary *replyPage;

@property(nonatomic,strong)NSMutableDictionary *zans;

@property(nonatomic,strong)NSString *location;

@property(nonatomic,assign)bool hasShowAll;

@end

2.計算每個cell

@interface ShareInfoFrame : NSObject

@property(nonatomic,strong)ShareInfoDemo *shareInfo;

@property(nonatomic,assign)CGRect iconImageFrame;

@property(nonatomic,assign)CGRect nameFrame;

@property(nonatomic,assign)CGRect contentFrame;

@property(nonatomic,strong)NSMutableArray * imageViewFArr;

@property(nonatomic,assign)CGRect mapFrame;

@property(nonatomic,assign)CGRect playviewFrame;

@property(nonatomic,assign)CGRect timeFrame;

@property(nonatomic,assign)CGRect blogToolBarF;

@property(nonatomic,strong)NSMutableArray *responseViewHeightArr;

@property(nonatomic,assign)CGFloat cellHeight;

@property(nonatomic,assign)CGRect zanFrame;

@property(nonatomic,assign)CGRect playSoundFrame;

@property(nonatomic,assign)CGRect delectFrame;

@property(nonatomic,assign)CGRect showAllFrame;

@end


.m文件

-(NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString {

? NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];? ? NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];? ? return responseJSON;

}

-(void)setShareInfo:(ShareInfoDemo *)shareInfo{??

_shareInfo=shareInfo;? ?

self.imageViewFArr=[[NSMutableArray alloc]initWithCapacity:0];? ? self.responseViewHeightArr=[[NSMutableArray alloc]initWithCapacity:0];? ? /

/頭像的Frame? ? CGFloat iconX = 20;? ? CGFloat iconY = 20;? ? CGFloat iconW = 40;? ? CGFloat iconH = 40;? ?

self.iconImageFrame=CGRectMake(iconX, iconY, iconW, iconH);? ?

//名字的Frame? ? CGFloat nameX = 70;? ? CGFloat nameY = 20;? ? CGFloat nameW = YBScreenBoundsWidth-90;? ? CGFloat nameH =15;??

self.nameFrame = CGRectMake(nameX, nameY, nameW, nameH);? ?

//文字內(nèi)容的Frame? ? CGFloat contentX=70;? ? CGFloat contentY=40;? ? CGFloat contentW=YBScreenBoundsWidth-90;? ? CGSize size1 = CGSizeMake(YBScreenBoundsWidth-90, MAXFLOAT);? ?

NSDictionary *dict = @{NSFontAttributeName:ContentFont};? ?

CGSize size2 =[self.shareInfo.content boundingRectWithSize:size1 options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;? ? CGFloat contentH = size2.height;? ? ??

self.contentFrame=CGRectMake(contentX, contentY, contentW, contentH);?

? if (contentH>90) {? ? ? ? if (!self.shareInfo.hasShowAll) {? ? ? ? ? ?? self.contentFrame=CGRectMake(contentX, contentY, contentW, 90);? ? ??

}? ? }? ? //富文本內(nèi)容的Frame//? ? bool isOver=NO;//? ? if (size2.height+40<60) {//? ? ? ? isOver=NO;//? ?

}else{//? ? ? ? isOver=YES;//??

}? ? if ([self.shareInfo.type isEqualToString:@"TEXT"]) {??

? ? if([self.shareInfo.content containsString:@"{"]){? ? ? ? ?

? NSDictionary *dic=[self parseJSONStringToNSDictionary:self.shareInfo.content];? ? ? ? ? ? //文字內(nèi)容的Frame? ? ? ? ? ? CGFloat contentX=70;? ? ? ? ? ? CGFloat contentY=40;? ? ? ? ? ? CGFloat contentW=YBScreenBoundsWidth-90;? ? ? ? ? ? CGSize size1 = CGSizeMake(YBScreenBoundsWidth-90, MAXFLOAT);? ? ? ? ? ? NSDictionary *dict = @{NSFontAttributeName:ContentFont};? ? ? ? ? ? CGSize size2 =[[NSString stringWithFormat:@"%@%@",dic[@"user"][@"name"],dic[@"message"]] boundingRectWithSize:size1 options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;? ? ? ? ? ? CGFloat contentH = size2.height;? ? ? ? ? ? self.contentFrame=CGRectMake(contentX, contentY, contentW, contentH);//? ? ? ? ? ? if (contentH>90) {//? ? ? ? ? ? ? ? if (!self.shareInfo.hasShowAll) {//? ? ? ? ? ? ? ? ? ? self.contentFrame=CGRectMake(contentX, contentY, contentW, 90);//? ? ? ? ? ? ? ? }//? ? ? ? ? ? }? ? ? ? ? ? ? ? ? ? }? ? ? ? self.timeFrame=CGRectMake(70, CGRectGetMaxY(self.contentFrame)+10, 60,20);? ? ? ? self.blogToolBarF=CGRectMake(YBScreenBoundsWidth-20-22, CGRectGetMaxY(self.contentFrame)+10, 22, 13);? ? ? ? NSMutableString *mstr=[[NSMutableString alloc]initWithCapacity:0];? ? ? ? for (int i=0; i90&&![self.shareInfo.content containsString:@"{"]) {

self.showAllFrame=CGRectMake(210, self.timeFrame.origin.y-2, 60, 25);

}

NSArray *listArr=self.shareInfo.replyPage[@"list"];

if (![listArr isKindOfClass:[NSNull class]]) {

NSValue *lasevalue=[self.responseViewHeightArr lastObject];

CGRect rect=[lasevalue CGRectValue];

self.cellHeight=CGRectGetMaxY(rect)+20;

}else{

if (self.shareInfo.zans.allKeys.count==0) {

self.cellHeight=CGRectGetMaxY(self.timeFrame)+20;

}else{

self.cellHeight=CGRectGetMaxY(self.zanFrame)+20;

}

}

if (listArr.count==0) {

if (self.shareInfo.zans.allKeys.count==0) {

self.cellHeight=CGRectGetMaxY(self.timeFrame)+20;

}else{

self.cellHeight=CGRectGetMaxY(self.zanFrame)+20;

}

}

}


總結(jié):看起來難的東西沪编,只要思路對了就好了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末呼盆,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子漾抬,更是在濱河造成了極大的恐慌宿亡,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,919評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件纳令,死亡現(xiàn)場離奇詭異挽荠,居然都是意外死亡克胳,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,567評論 3 392
  • 文/潘曉璐 我一進店門圈匆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來漠另,“玉大人,你說我怎么就攤上這事跃赚“蚀辏” “怎么了?”我有些...
    開封第一講書人閱讀 163,316評論 0 353
  • 文/不壞的土叔 我叫張陵纬傲,是天一觀的道長满败。 經(jīng)常有香客問我,道長叹括,這世上最難降的妖魔是什么算墨? 我笑而不...
    開封第一講書人閱讀 58,294評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮汁雷,結(jié)果婚禮上净嘀,老公的妹妹穿的比我還像新娘。我一直安慰自己侠讯,他們只是感情好挖藏,可當(dāng)我...
    茶點故事閱讀 67,318評論 6 390
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著厢漩,像睡著了一般膜眠。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上溜嗜,一...
    開封第一講書人閱讀 51,245評論 1 299
  • 那天柴底,我揣著相機與錄音,去河邊找鬼粱胜。 笑死柄驻,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的焙压。 我是一名探鬼主播鸿脓,決...
    沈念sama閱讀 40,120評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼涯曲!你這毒婦竟也來了野哭?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,964評論 0 275
  • 序言:老撾萬榮一對情侶失蹤幻件,失蹤者是張志新(化名)和其女友劉穎拨黔,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绰沥,經(jīng)...
    沈念sama閱讀 45,376評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡篱蝇,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,592評論 2 333
  • 正文 我和宋清朗相戀三年贺待,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片零截。...
    茶點故事閱讀 39,764評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡麸塞,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出涧衙,到底是詐尸還是另有隱情哪工,我是刑警寧澤,帶...
    沈念sama閱讀 35,460評論 5 344
  • 正文 年R本政府宣布弧哎,位于F島的核電站雁比,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏撤嫩。R本人自食惡果不足惜章贞,卻給世界環(huán)境...
    茶點故事閱讀 41,070評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望非洲。 院中可真熱鬧,春花似錦蜕径、人聲如沸两踏。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,697評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梦染。三九已至,卻和暖如春朴皆,著一層夾襖步出監(jiān)牢的瞬間帕识,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,846評論 1 269
  • 我被黑心中介騙來泰國打工遂铡, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留肮疗,地道東北人。 一個月前我還...
    沈念sama閱讀 47,819評論 2 370
  • 正文 我出身青樓扒接,卻偏偏與公主長得像伪货,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子钾怔,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,665評論 2 354

推薦閱讀更多精彩內(nèi)容