| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- //
- // LogFrame.m
- // IBOSS
- //
- // Created by guan hong hou on 16/1/7.
- // Copyright © 2016年 elongtian. All rights reserved.
- //
- #import "LogFrame.h"
- #import "NSString+Tools.h"
- #import "ReplyFrame.h"
- #define kTextFont [UIFont systemFontOfSize:14]
- #define commentTextFont [UIFont systemFontOfSize:12]
- #define logContentTextFont [UIFont systemFontOfSize:13]
- @implementation LogFrame
- //设置日志布局
- -(void)setLogModel:(Log *)logModel
- {
- _log=logModel;
- CGFloat padding =5;
- CGFloat xpadding =5;
- CGFloat ypadding =5;
- CGFloat usernamepadding=10;
- NSDictionary *logDict = @{NSFontAttributeName:kTextFont};
- NSDictionary *logContentDict = @{NSFontAttributeName:logContentTextFont};
- //用户名frame
- NSString *userName= [_log userName];
- CGRect userNameFrame = [userName textRectWithSize:CGSizeMake(80, MAXFLOAT) attributes:logDict];
-
- userNameFrame.origin.x =25;
- userNameFrame.origin.y = usernamepadding;
- _userNameLabelF = userNameFrame;
-
- //头像frame
- CGRect headImgFrame = CGRectMake(xpadding,CGRectGetMaxY(_userNameLabelF),15,18);
- _headImgF=headImgFrame;
-
- //评论标识frame
- NSString *commentFlag= [_log recordStatus];
- CGRect commentFlagFrame = [commentFlag textRectWithSize:CGSizeMake(80, MAXFLOAT) attributes:logDict];
-
- commentFlagFrame.origin.x =Screen_Width-commentFlagFrame.size.width-20;
- commentFlagFrame.origin.y = usernamepadding;
- _commentFlagLabelF=commentFlagFrame;
-
- //创建日期frame
- CGRect logDateF=CGRectMake(userNameFrame.origin.x,CGRectGetMaxY(_headImgF) ,200,25);
- _dateLabelF=logDateF;
-
- //当前位置frame
- NSString *location=[_log location];
- NSDictionary *commentDict = @{NSFontAttributeName:commentTextFont};
- if(location!=nil&&location.length>0){
- CGRect locationImgFrame=CGRectMake(Screen_Width-150, CGRectGetMaxY(_headImgF)+3,13,16);
- _locationImgF=locationImgFrame;
- CGRect locationFrame = [location textRectWithSize:CGSizeMake(Screen_Width-CGRectGetMaxX(_locationImgF)-5, MAXFLOAT) attributes:commentDict];
-
- locationFrame.origin.x =CGRectGetMaxX(_locationImgF)+padding;
- locationFrame.origin.y = CGRectGetMaxY(_headImgF)+3;
- _locationContentF=locationFrame;
- }
-
- //内容frame
- NSString *content=[_log content];
- if(content!=nil&&content.length>0){
- CGRect contentFrame = [content textRectWithSize:CGSizeMake(Screen_Width-CGRectGetMaxX(_headImgF)-padding, MAXFLOAT) attributes:logContentDict];
-
- contentFrame.origin.x =_userNameLabelF.origin.x;
- contentFrame.origin.y = CGRectGetMaxY(_dateLabelF)+ypadding;
- _contentLabelF=contentFrame;
- }
- //评论内容frame
- NSString *commentContent= [_log remarks];
- //回复数组
- NSMutableArray *replyArray= [_log replyArray];
- //图片存在
- if(_log.imagePathArray!=nil &&[_log.imagePathArray count]>0 ){
-
- /*
- 获得图片frame
- */
- CGFloat xPhoto =_userNameLabelF.origin.x;
- CGFloat yPhoto =CGRectGetMaxY(_contentLabelF) +padding;
- CGRect photoCollectionViewFrame = CGRectMake(xPhoto,yPhoto, Screen_Width-40, [self getPhotoCollectionViewHeightWithPhotos:_log.imagePathArray]);
- _logImageF= photoCollectionViewFrame;
-
- //声音存在
- if(_log.soundArray!=nil&&_log.soundArray.count>0){
- //语音frame
- CGFloat xSound=xPhoto;
- CGFloat ySound =CGRectGetMaxY(_logImageF)+padding;
- CGRect soundViewFrame = CGRectMake(xSound,ySound,300, [self getSoundViewHeight:_log.soundArray]);
- _logSoundF=soundViewFrame;
-
- CGRect commentWordFrame=CGRectMake(Screen_Width-50,ySound+10,40,30);
- _commentWordF=commentWordFrame;
-
- CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,ySound+17,17,17);
- //评论图片frame
- _commentBtnImgF=commentImgFrame;
- CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,ySound+10,40,30);
- _replyWordF=replyWordFrame;
-
- CGRect replyImgFrame=CGRectMake(_replyWordF.origin.x-padding-17,ySound+18,17,17);
- _replyImgF=replyImgFrame;
-
- //评论内容 存在
- if(commentContent!=nil&&commentContent.length>0){
- //评论者frame
- _reviewerF=CGRectMake(_logSoundF.origin.x,CGRectGetMaxY(_logSoundF)+padding+2,200, 25);
- NSString *commentDate=[_log commentUpdateTime];
- //评论日期存在
- if(commentDate!=nil&&commentDate.length>0){
- CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
-
- commentDateFrame.origin.x =Screen_Width-150;
- commentDateFrame.origin.y = CGRectGetMaxY(_logSoundF)+padding+4;
- _commentDateF=commentDateFrame;
- }
- //评论内容
- CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x, CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width-_reviewerF.origin.x-padding,40);
- _logCommentF=commentContentFrame;
- //回复信息存在
- if(replyArray!=nil&&[replyArray count]>0){
- //回复信息frame
- CGFloat xReply= _reviewerF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- //底部分隔线frame
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- //cell高度
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //回复信息不存在,底部分隔线frame和单元格高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
-
- }
- else{
- //评论内容不存在,回复内容存在
- if(replyArray!=nil&&[replyArray count]>0){
- //回复内容frame
- CGFloat xReply= _logSoundF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logSoundF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
- //底部分隔线frame
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
-
- //单元格高度
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //评论内容不存在,回复内容不存在,底部分隔线frame,单元格高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logSoundF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
- }
-
-
- }
-
- else{
- //声音不存在
- //回复图片frame,评论图片frame
-
- CGRect commentWordFrame=CGRectMake(Screen_Width-50,CGRectGetMaxY(_logImageF)+10,40,30);
- _commentWordF=commentWordFrame;
-
- CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,CGRectGetMaxY(_logImageF)+17,17,17);
- //评论图片frame
- _commentBtnImgF=commentImgFrame;
- CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,CGRectGetMaxY(_logImageF)+10,40,30);
- _replyWordF=replyWordFrame;
-
- CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,CGRectGetMaxY(_logImageF)+18,17,17);
- _replyImgF=replyImgFrame;
-
- //评论内容存在
- if(commentContent!=nil&&commentContent.length>0){
- //评论者frame
- _reviewerF=CGRectMake( _logImageF.origin.x,CGRectGetMaxY(_replyImgF)+padding,200, 25);
- NSString *commentDate=[_log commentUpdateTime];
- //评论日期frame
- if(commentDate!=nil&&commentDate.length>0){
- CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
-
- commentDateFrame.origin.x =Screen_Width-150;
- commentDateFrame.origin.y = CGRectGetMaxY(_replyImgF)+padding+2;
- _commentDateF=commentDateFrame;
- }
- //评论内容frame
- CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x, CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width-_reviewerF.origin.x-padding, 40);
- _logCommentF=commentContentFrame;
- //回复内容存在,获得回复内容frame,底部分隔线frame,cell高度
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _reviewerF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //回复内容不存在,底部分隔线frame,cell高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
-
- }
- else{
- //评论内容不存在,回复内容存在,获得回复内容frame,底部分隔线frame,cell高度
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _logImageF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_replyImgF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //回复内容不存在,底部分隔线frame,cell高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_replyImgF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
- }
- }
-
- }
-
- else{
- //图片不存在,声音存在
- if(_log.soundArray!=nil&&_log.soundArray.count>0){
- //声音frame
- CGFloat xSound= _contentLabelF.origin.x;
- CGFloat ySound =CGRectGetMaxY(_contentLabelF)+padding;
- CGRect soundViewFrame = CGRectMake(xSound,ySound,300, [self getSoundViewHeight:_log.soundArray]);
- _logSoundF=soundViewFrame;
- //回复按钮frame
- CGRect commentWordFrame=CGRectMake(Screen_Width-50,ySound+10,40,30);
- _commentWordF=commentWordFrame;
-
- CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,ySound+17,17,17);
- //评论图片frame
- _commentBtnImgF=commentImgFrame;
- CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,ySound+10,40,30);
- _replyWordF=replyWordFrame;
-
- CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,ySound+18,17,17);
- _replyImgF=replyImgFrame;
- //评论内容存在
- if(commentContent!=nil&&commentContent.length>0){
- //评论者frame
- _reviewerF=CGRectMake(_logSoundF.origin.x,CGRectGetMaxY(_logSoundF)+padding+2,200, 25);
- NSString *commentDate=[_log commentUpdateTime];
- //评论日期frame
- if(commentDate!=nil&&commentDate.length>0){
- CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
-
- commentDateFrame.origin.x =Screen_Width-150;
- commentDateFrame.origin.y = CGRectGetMaxY(_logSoundF)+padding+4;
- _commentDateF=commentDateFrame;
- }
- //评论内容frame
- CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x,CGRectGetMaxY(_reviewerF)+ypadding,Screen_Width-_reviewerF.origin.x-padding,40);
- _logCommentF=commentContentFrame;
- //回复内容存在,回复内容frame,底部分隔线frame,单元格高度
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _reviewerF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //回复内容不存在,底部分隔线frame,单元格高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
-
- }
- else{
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _logSoundF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logSoundF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logSoundF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
- }
-
-
- }
- else{
- //图片不存在,声音不存在,回复按钮frame,评论按钮frame
-
- CGRect commentWordFrame=CGRectMake(Screen_Width-50,CGRectGetMaxY(_contentLabelF)+10,40,30);
- _commentWordF=commentWordFrame;
-
- CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,CGRectGetMaxY(_contentLabelF)+17,17,17);
- //评论图片frame
- _commentBtnImgF=commentImgFrame;
- CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,CGRectGetMaxY(_contentLabelF)+10,40,30);
- _replyWordF=replyWordFrame;
-
- CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,CGRectGetMaxY(_contentLabelF)+18,17,17);
- _replyImgF=replyImgFrame;
- //评论内容存在
- if(commentContent!=nil&&commentContent.length>0){
- //评论者frame
- _reviewerF=CGRectMake(_contentLabelF.origin.x,CGRectGetMaxY(_replyImgF)+padding+2,200, 25);
- NSString *commentDate=[_log commentUpdateTime];
- //评论日期frame
- if(commentDate!=nil&&commentDate.length>0){
- CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
-
- commentDateFrame.origin.x =Screen_Width-150;
- commentDateFrame.origin.y = CGRectGetMaxY(_replyImgF)+padding+4;
- _commentDateF=commentDateFrame;
- }
- //评论内容frame
-
- CGRect commentContentFrame=CGRectMake( _reviewerF.origin.x,CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width- _reviewerF.origin.x-padding,40);
- _logCommentF=commentContentFrame;
- //回复内容存在,底部分隔线frame,单元格高度
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _reviewerF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //回复内容不存在,底部分隔线frame,单元格高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
-
- }
- else{
- //评论内容不存在,回复内容存在,底部分隔线frame,单元格高度
- if(replyArray!=nil&&[replyArray count]>0){
- CGFloat xReply= _contentLabelF.origin.x;
- CGFloat yReply=CGRectGetMaxY(_replyImgF)+padding;
- CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
- _logReplyContentF=replyRect;
-
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
-
- }
- else{
- //评论内容不存在,回复内容不存在,底部分隔线frame,单元格高度
- CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_replyImgF)+padding, Screen_Width, 10);
- _separatorsF=separatorF;
- _cellHeight=CGRectGetMaxY(_separatorsF);
- }
- }
- }
- }
-
-
-
-
- }
- //获得collectionviewcell的总高度
- - (CGFloat)getPhotoCollectionViewHeightWithPhotos:(NSMutableArray *)photos {
- // 上下间隔已经在frame上做了
- NSInteger row = (photos.count / 3 + (photos.count % 3 ? 1 : 0));
- return (row *85 + (row *10));
- }
- //获得语音tableviewcell的总高度
- - (CGFloat)getSoundViewHeight:(NSMutableArray *)soundArray {
- // 上下间隔已经在frame上做了
- NSInteger row = soundArray.count;
- return (row *50 + (row *10));
- }
- //获得回复信息的总高度
- - (CGFloat)getReplyHeight:(NSMutableArray *)replyArray {
- // 上下间隔已经在frame上做了
- CGFloat total=0;
- for(int i=0;i<replyArray.count;i++){
- ReplyFrame *replyFrame= [replyArray objectAtIndex:i];
- CGFloat cellHeight=[replyFrame cellHeight];
- total+=cellHeight;
- }
- return total;
-
- }
- @end
|