LogFrame.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. //
  2. // LogFrame.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 16/1/7.
  6. // Copyright © 2016年 elongtian. All rights reserved.
  7. //
  8. #import "LogFrame.h"
  9. #import "NSString+Tools.h"
  10. #import "ReplyFrame.h"
  11. #define kTextFont [UIFont systemFontOfSize:14]
  12. #define commentTextFont [UIFont systemFontOfSize:12]
  13. #define logContentTextFont [UIFont systemFontOfSize:13]
  14. @implementation LogFrame
  15. //设置日志布局
  16. -(void)setLogModel:(Log *)logModel
  17. {
  18. _log=logModel;
  19. CGFloat padding =5;
  20. CGFloat xpadding =5;
  21. CGFloat ypadding =5;
  22. CGFloat usernamepadding=10;
  23. NSDictionary *logDict = @{NSFontAttributeName:kTextFont};
  24. NSDictionary *logContentDict = @{NSFontAttributeName:logContentTextFont};
  25. //用户名frame
  26. NSString *userName= [_log userName];
  27. CGRect userNameFrame = [userName textRectWithSize:CGSizeMake(80, MAXFLOAT) attributes:logDict];
  28. userNameFrame.origin.x =25;
  29. userNameFrame.origin.y = usernamepadding;
  30. _userNameLabelF = userNameFrame;
  31. //头像frame
  32. CGRect headImgFrame = CGRectMake(xpadding,CGRectGetMaxY(_userNameLabelF),15,18);
  33. _headImgF=headImgFrame;
  34. //评论标识frame
  35. NSString *commentFlag= [_log recordStatus];
  36. CGRect commentFlagFrame = [commentFlag textRectWithSize:CGSizeMake(80, MAXFLOAT) attributes:logDict];
  37. commentFlagFrame.origin.x =Screen_Width-commentFlagFrame.size.width-20;
  38. commentFlagFrame.origin.y = usernamepadding;
  39. _commentFlagLabelF=commentFlagFrame;
  40. //创建日期frame
  41. CGRect logDateF=CGRectMake(userNameFrame.origin.x,CGRectGetMaxY(_headImgF) ,200,25);
  42. _dateLabelF=logDateF;
  43. //当前位置frame
  44. NSString *location=[_log location];
  45. NSDictionary *commentDict = @{NSFontAttributeName:commentTextFont};
  46. if(location!=nil&&location.length>0){
  47. CGRect locationImgFrame=CGRectMake(Screen_Width-150, CGRectGetMaxY(_headImgF)+3,13,16);
  48. _locationImgF=locationImgFrame;
  49. CGRect locationFrame = [location textRectWithSize:CGSizeMake(Screen_Width-CGRectGetMaxX(_locationImgF)-5, MAXFLOAT) attributes:commentDict];
  50. locationFrame.origin.x =CGRectGetMaxX(_locationImgF)+padding;
  51. locationFrame.origin.y = CGRectGetMaxY(_headImgF)+3;
  52. _locationContentF=locationFrame;
  53. }
  54. //内容frame
  55. NSString *content=[_log content];
  56. if(content!=nil&&content.length>0){
  57. CGRect contentFrame = [content textRectWithSize:CGSizeMake(Screen_Width-CGRectGetMaxX(_headImgF)-padding, MAXFLOAT) attributes:logContentDict];
  58. contentFrame.origin.x =_userNameLabelF.origin.x;
  59. contentFrame.origin.y = CGRectGetMaxY(_dateLabelF)+ypadding;
  60. _contentLabelF=contentFrame;
  61. }
  62. //评论内容frame
  63. NSString *commentContent= [_log remarks];
  64. //回复数组
  65. NSMutableArray *replyArray= [_log replyArray];
  66. //图片存在
  67. if(_log.imagePathArray!=nil &&[_log.imagePathArray count]>0 ){
  68. /*
  69. 获得图片frame
  70. */
  71. CGFloat xPhoto =_userNameLabelF.origin.x;
  72. CGFloat yPhoto =CGRectGetMaxY(_contentLabelF) +padding;
  73. CGRect photoCollectionViewFrame = CGRectMake(xPhoto,yPhoto, Screen_Width-40, [self getPhotoCollectionViewHeightWithPhotos:_log.imagePathArray]);
  74. _logImageF= photoCollectionViewFrame;
  75. //声音存在
  76. if(_log.soundArray!=nil&&_log.soundArray.count>0){
  77. //语音frame
  78. CGFloat xSound=xPhoto;
  79. CGFloat ySound =CGRectGetMaxY(_logImageF)+padding;
  80. CGRect soundViewFrame = CGRectMake(xSound,ySound,300, [self getSoundViewHeight:_log.soundArray]);
  81. _logSoundF=soundViewFrame;
  82. CGRect commentWordFrame=CGRectMake(Screen_Width-50,ySound+10,40,30);
  83. _commentWordF=commentWordFrame;
  84. CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,ySound+17,17,17);
  85. //评论图片frame
  86. _commentBtnImgF=commentImgFrame;
  87. CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,ySound+10,40,30);
  88. _replyWordF=replyWordFrame;
  89. CGRect replyImgFrame=CGRectMake(_replyWordF.origin.x-padding-17,ySound+18,17,17);
  90. _replyImgF=replyImgFrame;
  91. //评论内容 存在
  92. if(commentContent!=nil&&commentContent.length>0){
  93. //评论者frame
  94. _reviewerF=CGRectMake(_logSoundF.origin.x,CGRectGetMaxY(_logSoundF)+padding+2,200, 25);
  95. NSString *commentDate=[_log commentUpdateTime];
  96. //评论日期存在
  97. if(commentDate!=nil&&commentDate.length>0){
  98. CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
  99. commentDateFrame.origin.x =Screen_Width-150;
  100. commentDateFrame.origin.y = CGRectGetMaxY(_logSoundF)+padding+4;
  101. _commentDateF=commentDateFrame;
  102. }
  103. //评论内容
  104. CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x, CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width-_reviewerF.origin.x-padding,40);
  105. _logCommentF=commentContentFrame;
  106. //回复信息存在
  107. if(replyArray!=nil&&[replyArray count]>0){
  108. //回复信息frame
  109. CGFloat xReply= _reviewerF.origin.x;
  110. CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
  111. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  112. _logReplyContentF=replyRect;
  113. //底部分隔线frame
  114. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  115. _separatorsF=separatorF;
  116. //cell高度
  117. _cellHeight=CGRectGetMaxY(_separatorsF);
  118. }
  119. else{
  120. //回复信息不存在,底部分隔线frame和单元格高度
  121. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
  122. _separatorsF=separatorF;
  123. _cellHeight=CGRectGetMaxY(_separatorsF);
  124. }
  125. }
  126. else{
  127. //评论内容不存在,回复内容存在
  128. if(replyArray!=nil&&[replyArray count]>0){
  129. //回复内容frame
  130. CGFloat xReply= _logSoundF.origin.x;
  131. CGFloat yReply=CGRectGetMaxY(_logSoundF)+padding;
  132. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  133. _logReplyContentF=replyRect;
  134. //底部分隔线frame
  135. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  136. _separatorsF=separatorF;
  137. //单元格高度
  138. _cellHeight=CGRectGetMaxY(_separatorsF);
  139. }
  140. else{
  141. //评论内容不存在,回复内容不存在,底部分隔线frame,单元格高度
  142. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logSoundF)+padding, Screen_Width, 10);
  143. _separatorsF=separatorF;
  144. _cellHeight=CGRectGetMaxY(_separatorsF);
  145. }
  146. }
  147. }
  148. else{
  149. //声音不存在
  150. //回复图片frame,评论图片frame
  151. CGRect commentWordFrame=CGRectMake(Screen_Width-50,CGRectGetMaxY(_logImageF)+10,40,30);
  152. _commentWordF=commentWordFrame;
  153. CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,CGRectGetMaxY(_logImageF)+17,17,17);
  154. //评论图片frame
  155. _commentBtnImgF=commentImgFrame;
  156. CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,CGRectGetMaxY(_logImageF)+10,40,30);
  157. _replyWordF=replyWordFrame;
  158. CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,CGRectGetMaxY(_logImageF)+18,17,17);
  159. _replyImgF=replyImgFrame;
  160. //评论内容存在
  161. if(commentContent!=nil&&commentContent.length>0){
  162. //评论者frame
  163. _reviewerF=CGRectMake( _logImageF.origin.x,CGRectGetMaxY(_replyImgF)+padding,200, 25);
  164. NSString *commentDate=[_log commentUpdateTime];
  165. //评论日期frame
  166. if(commentDate!=nil&&commentDate.length>0){
  167. CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
  168. commentDateFrame.origin.x =Screen_Width-150;
  169. commentDateFrame.origin.y = CGRectGetMaxY(_replyImgF)+padding+2;
  170. _commentDateF=commentDateFrame;
  171. }
  172. //评论内容frame
  173. CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x, CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width-_reviewerF.origin.x-padding, 40);
  174. _logCommentF=commentContentFrame;
  175. //回复内容存在,获得回复内容frame,底部分隔线frame,cell高度
  176. if(replyArray!=nil&&[replyArray count]>0){
  177. CGFloat xReply= _reviewerF.origin.x;
  178. CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
  179. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  180. _logReplyContentF=replyRect;
  181. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  182. _separatorsF=separatorF;
  183. _cellHeight=CGRectGetMaxY(_separatorsF);
  184. }
  185. else{
  186. //回复内容不存在,底部分隔线frame,cell高度
  187. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
  188. _separatorsF=separatorF;
  189. _cellHeight=CGRectGetMaxY(_separatorsF);
  190. }
  191. }
  192. else{
  193. //评论内容不存在,回复内容存在,获得回复内容frame,底部分隔线frame,cell高度
  194. if(replyArray!=nil&&[replyArray count]>0){
  195. CGFloat xReply= _logImageF.origin.x;
  196. CGFloat yReply=CGRectGetMaxY(_replyImgF)+padding;
  197. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  198. _logReplyContentF=replyRect;
  199. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  200. _separatorsF=separatorF;
  201. _cellHeight=CGRectGetMaxY(_separatorsF);
  202. }
  203. else{
  204. //回复内容不存在,底部分隔线frame,cell高度
  205. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_replyImgF)+padding, Screen_Width, 10);
  206. _separatorsF=separatorF;
  207. _cellHeight=CGRectGetMaxY(_separatorsF);
  208. }
  209. }
  210. }
  211. }
  212. else{
  213. //图片不存在,声音存在
  214. if(_log.soundArray!=nil&&_log.soundArray.count>0){
  215. //声音frame
  216. CGFloat xSound= _contentLabelF.origin.x;
  217. CGFloat ySound =CGRectGetMaxY(_contentLabelF)+padding;
  218. CGRect soundViewFrame = CGRectMake(xSound,ySound,300, [self getSoundViewHeight:_log.soundArray]);
  219. _logSoundF=soundViewFrame;
  220. //回复按钮frame
  221. CGRect commentWordFrame=CGRectMake(Screen_Width-50,ySound+10,40,30);
  222. _commentWordF=commentWordFrame;
  223. CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,ySound+17,17,17);
  224. //评论图片frame
  225. _commentBtnImgF=commentImgFrame;
  226. CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,ySound+10,40,30);
  227. _replyWordF=replyWordFrame;
  228. CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,ySound+18,17,17);
  229. _replyImgF=replyImgFrame;
  230. //评论内容存在
  231. if(commentContent!=nil&&commentContent.length>0){
  232. //评论者frame
  233. _reviewerF=CGRectMake(_logSoundF.origin.x,CGRectGetMaxY(_logSoundF)+padding+2,200, 25);
  234. NSString *commentDate=[_log commentUpdateTime];
  235. //评论日期frame
  236. if(commentDate!=nil&&commentDate.length>0){
  237. CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
  238. commentDateFrame.origin.x =Screen_Width-150;
  239. commentDateFrame.origin.y = CGRectGetMaxY(_logSoundF)+padding+4;
  240. _commentDateF=commentDateFrame;
  241. }
  242. //评论内容frame
  243. CGRect commentContentFrame=CGRectMake(_reviewerF.origin.x,CGRectGetMaxY(_reviewerF)+ypadding,Screen_Width-_reviewerF.origin.x-padding,40);
  244. _logCommentF=commentContentFrame;
  245. //回复内容存在,回复内容frame,底部分隔线frame,单元格高度
  246. if(replyArray!=nil&&[replyArray count]>0){
  247. CGFloat xReply= _reviewerF.origin.x;
  248. CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
  249. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  250. _logReplyContentF=replyRect;
  251. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  252. _separatorsF=separatorF;
  253. _cellHeight=CGRectGetMaxY(_separatorsF);
  254. }
  255. else{
  256. //回复内容不存在,底部分隔线frame,单元格高度
  257. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
  258. _separatorsF=separatorF;
  259. _cellHeight=CGRectGetMaxY(_separatorsF);
  260. }
  261. }
  262. else{
  263. if(replyArray!=nil&&[replyArray count]>0){
  264. CGFloat xReply= _logSoundF.origin.x;
  265. CGFloat yReply=CGRectGetMaxY(_logSoundF)+padding;
  266. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  267. _logReplyContentF=replyRect;
  268. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  269. _separatorsF=separatorF;
  270. _cellHeight=CGRectGetMaxY(_separatorsF);
  271. }
  272. else{
  273. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logSoundF)+padding, Screen_Width, 10);
  274. _separatorsF=separatorF;
  275. _cellHeight=CGRectGetMaxY(_separatorsF);
  276. }
  277. }
  278. }
  279. else{
  280. //图片不存在,声音不存在,回复按钮frame,评论按钮frame
  281. CGRect commentWordFrame=CGRectMake(Screen_Width-50,CGRectGetMaxY(_contentLabelF)+10,40,30);
  282. _commentWordF=commentWordFrame;
  283. CGRect commentImgFrame=CGRectMake(commentWordFrame.origin.x-padding-17,CGRectGetMaxY(_contentLabelF)+17,17,17);
  284. //评论图片frame
  285. _commentBtnImgF=commentImgFrame;
  286. CGRect replyWordFrame=CGRectMake(commentImgFrame.origin.x-40-padding,CGRectGetMaxY(_contentLabelF)+10,40,30);
  287. _replyWordF=replyWordFrame;
  288. CGRect replyImgFrame=CGRectMake( _replyWordF.origin.x-padding-17,CGRectGetMaxY(_contentLabelF)+18,17,17);
  289. _replyImgF=replyImgFrame;
  290. //评论内容存在
  291. if(commentContent!=nil&&commentContent.length>0){
  292. //评论者frame
  293. _reviewerF=CGRectMake(_contentLabelF.origin.x,CGRectGetMaxY(_replyImgF)+padding+2,200, 25);
  294. NSString *commentDate=[_log commentUpdateTime];
  295. //评论日期frame
  296. if(commentDate!=nil&&commentDate.length>0){
  297. CGRect commentDateFrame = [commentDate textRectWithSize:CGSizeMake(300, MAXFLOAT) attributes:commentDict];
  298. commentDateFrame.origin.x =Screen_Width-150;
  299. commentDateFrame.origin.y = CGRectGetMaxY(_replyImgF)+padding+4;
  300. _commentDateF=commentDateFrame;
  301. }
  302. //评论内容frame
  303. CGRect commentContentFrame=CGRectMake( _reviewerF.origin.x,CGRectGetMaxY(_reviewerF)+ypadding, Screen_Width- _reviewerF.origin.x-padding,40);
  304. _logCommentF=commentContentFrame;
  305. //回复内容存在,底部分隔线frame,单元格高度
  306. if(replyArray!=nil&&[replyArray count]>0){
  307. CGFloat xReply= _reviewerF.origin.x;
  308. CGFloat yReply=CGRectGetMaxY(_logCommentF)+padding;
  309. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  310. _logReplyContentF=replyRect;
  311. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  312. _separatorsF=separatorF;
  313. _cellHeight=CGRectGetMaxY(_separatorsF);
  314. }
  315. else{
  316. //回复内容不存在,底部分隔线frame,单元格高度
  317. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logCommentF)+padding, Screen_Width, 10);
  318. _separatorsF=separatorF;
  319. _cellHeight=CGRectGetMaxY(_separatorsF);
  320. }
  321. }
  322. else{
  323. //评论内容不存在,回复内容存在,底部分隔线frame,单元格高度
  324. if(replyArray!=nil&&[replyArray count]>0){
  325. CGFloat xReply= _contentLabelF.origin.x;
  326. CGFloat yReply=CGRectGetMaxY(_replyImgF)+padding;
  327. CGRect replyRect=CGRectMake(xReply, yReply,Screen_Width,[self getReplyHeight:replyArray]);
  328. _logReplyContentF=replyRect;
  329. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_logReplyContentF)+padding, Screen_Width, 10);
  330. _separatorsF=separatorF;
  331. _cellHeight=CGRectGetMaxY(_separatorsF);
  332. }
  333. else{
  334. //评论内容不存在,回复内容不存在,底部分隔线frame,单元格高度
  335. CGRect separatorF=CGRectMake(0,CGRectGetMaxY(_replyImgF)+padding, Screen_Width, 10);
  336. _separatorsF=separatorF;
  337. _cellHeight=CGRectGetMaxY(_separatorsF);
  338. }
  339. }
  340. }
  341. }
  342. }
  343. //获得collectionviewcell的总高度
  344. - (CGFloat)getPhotoCollectionViewHeightWithPhotos:(NSMutableArray *)photos {
  345. // 上下间隔已经在frame上做了
  346. NSInteger row = (photos.count / 3 + (photos.count % 3 ? 1 : 0));
  347. return (row *85 + (row *10));
  348. }
  349. //获得语音tableviewcell的总高度
  350. - (CGFloat)getSoundViewHeight:(NSMutableArray *)soundArray {
  351. // 上下间隔已经在frame上做了
  352. NSInteger row = soundArray.count;
  353. return (row *50 + (row *10));
  354. }
  355. //获得回复信息的总高度
  356. - (CGFloat)getReplyHeight:(NSMutableArray *)replyArray {
  357. // 上下间隔已经在frame上做了
  358. CGFloat total=0;
  359. for(int i=0;i<replyArray.count;i++){
  360. ReplyFrame *replyFrame= [replyArray objectAtIndex:i];
  361. CGFloat cellHeight=[replyFrame cellHeight];
  362. total+=cellHeight;
  363. }
  364. return total;
  365. }
  366. @end