2
0

YMIMBaseMessageCell.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #import "YMIMBaseMessageCell.h"
  2. #import "SLMikeSegment.h"
  3. #import "SLMessageViewController.h"
  4. #import "SLMikeSegmentModel.h"
  5. #import "SLDecodeGifImage.h"
  6. @interface YMIMBaseMessageCell()
  7. @property (nonatomic, strong) MessageModel *msgModel;
  8. @end
  9. @implementation YMIMBaseMessageCell
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self confignMessageView];
  15. }
  16. return self;
  17. }
  18. - (void)confignMessageView
  19. {
  20. [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
  21. make.right.mas_equalTo(-8);
  22. make.top.mas_equalTo(0);
  23. make.width.height.mas_equalTo(48);
  24. }];
  25. [self.mikeLabelBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.right.equalTo(self.msgHeaderView.mas_left).offset(-8);
  27. make.left.mas_greaterThanOrEqualTo(16);
  28. make.top.mas_equalTo(6);
  29. make.height.mas_equalTo(46);
  30. make.width.mas_equalTo(100);
  31. }];
  32. [self.mikeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.centerY.equalTo(self.mikeLabelBgView);
  34. make.left.mas_equalTo(12);
  35. }];
  36. [self.mikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.centerY.equalTo(self.mikeLabelBgView);
  38. make.left.equalTo(self.mikeImageView.mas_right);
  39. }];
  40. [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  41. make.right.equalTo(self.msgHeaderView.mas_left).offset(-8);
  42. make.left.mas_greaterThanOrEqualTo(56);
  43. make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
  44. }];
  45. [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  46. make.top.left.mas_equalTo(10);
  47. make.right.bottom.mas_equalTo(-12);
  48. }];
  49. [self timeLabel];
  50. }
  51. - (void)removeAllConstViewHierarchy:(UIView *)superView
  52. {
  53. for (UIView *subview in superView.subviews)
  54. {
  55. [self removeAllConstViewHierarchy:subview];
  56. NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:subview];
  57. for (MASConstraint *constraint in installedConstraints) {
  58. [constraint uninstall];
  59. }
  60. }
  61. }
  62. - (void)confignBaseMessageContentWith:(MessageModel *)msgModel receiveHeardImg:(NSString *)img {
  63. self.msgModel = msgModel;
  64. self.messageLabel.text = msgModel.sendText;
  65. [self removeAllConstViewHierarchy:self.contentView];
  66. CGFloat topTimeHeight = 0.f;
  67. if (msgModel.showTime) {
  68. NSString *timeStr = [NSString stringWithFormat:@"%f",msgModel.sendTime * 1000];
  69. CGFloat nowDate = [[NSDate date] timeIntervalSince1970];
  70. if (nowDate - msgModel.sendTime > 60 * 60 * 24) {
  71. self.timeLabel.text = [NSString timeFromFormatter:@"M月d日 H:mm" timeString:timeStr];
  72. }else {
  73. self.timeLabel.text = [NSString timeFromFormatter:@"H:mm" timeString:timeStr];
  74. }
  75. topTimeHeight = 23.f;
  76. [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  77. make.top.left.right.equalTo(self.contentView);
  78. make.height.mas_equalTo(topTimeHeight);
  79. }];
  80. }else {
  81. self.timeLabel.text = @"";
  82. [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  83. make.top.left.right.equalTo(self.contentView);
  84. make.height.mas_equalTo(0);
  85. }];
  86. }
  87. if (_sendFailImageView) {
  88. [_sendFailImageView removeFromSuperview];
  89. _sendFailImageView = nil;
  90. }
  91. [self.mikeImageView stopAnimating];
  92. CGFloat topHeight = msgModel.showMike ? 46 : 0;
  93. CGFloat topMikeBg = (topHeight ? 6 : 0) + topTimeHeight;
  94. if (msgModel.isReceive) {
  95. NSArray *msgArr = [msgModel.sendText componentsSeparatedByString:@" "];
  96. NSInteger timeLong = ceil(msgArr.count / 2.5);
  97. {//你有多少数据量
  98. self.messageLabel.text = msgModel.showTrans ? msgModel.sendTextTrans : msgModel.sendText;
  99. if (!msgModel.showMike) {
  100. self.messageLabel.text = msgModel.sendText;
  101. }
  102. // self.messageLabel.textAlignment = NSTextAlignmentLeft;
  103. self.messageLabel.textColor = [UIColor blackColor];
  104. self.mikeLabel.textColor = [UIColor blackColor];
  105. self.mikeLabelBgView.backgroundColor = [UIColor whiteColor];
  106. self.messageLabelBgView.backgroundColor = [UIColor whiteColor];
  107. self.mikeImageView.image = ImageName(@"icon_msg_yy");
  108. if (msgModel.onBroadcast) {
  109. self.mikeImageView.image = [SLDecodeGifImage SharedInstance].msgYyAb;
  110. [self.mikeImageView startAnimating];
  111. }
  112. NSString *headUrl = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, img];
  113. [self.msgHeaderView sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:ImageName(@"icon_ellipse")];
  114. self.mikeLabel.text = [NSString stringWithFormat:@"%ld″",timeLong];
  115. if (!msgModel.showText) {
  116. [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  117. make.top.left.equalTo(self.messageLabelBgView).offset(10);
  118. // make.right.bottom.equalTo(self.messageLabelBgView).offset(-12);
  119. }];
  120. [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  121. make.left.equalTo(self.msgHeaderView.mas_right).offset(8);
  122. make.right.mas_lessThanOrEqualTo(self).offset(-56);
  123. make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
  124. make.height.mas_lessThanOrEqualTo(0.01);
  125. }];
  126. }else {
  127. [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  128. make.left.equalTo(self.msgHeaderView.mas_right).offset(8);
  129. make.right.mas_lessThanOrEqualTo(self).offset(-56);
  130. make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
  131. }];
  132. [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  133. make.top.left.equalTo(self.messageLabelBgView).offset(10);
  134. make.right.bottom.equalTo(self.messageLabelBgView).offset(-12);
  135. }];
  136. }
  137. }
  138. {
  139. [self.mikeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  140. make.centerY.equalTo(self.mikeLabelBgView);
  141. make.left.mas_equalTo(12);
  142. }];
  143. [self.mikeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  144. make.centerY.equalTo(self.mikeLabelBgView);
  145. make.left.equalTo(self.mikeImageView.mas_right);
  146. }];
  147. CGFloat mikeLabelWidth = 70.0f;
  148. if (timeLong > 0) {
  149. mikeLabelWidth = mikeLabelWidth + log(timeLong) * log(timeLong) * log(timeLong) * 4;
  150. mikeLabelWidth = MIN(kSCREEN_WIDTH * 3 / 5.0, mikeLabelWidth);
  151. // NSLog(@"--%f--%f--%f--%f--%f--%f--%f--%f--%f--%f",log(1),log(2),log(5),log(10),log(20),log(30),log(40),log(50),log(100),mikeLabelWidth);
  152. }
  153. [self.mikeLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  154. make.left.equalTo(self.msgHeaderView.mas_right).offset(8);
  155. make.right.mas_lessThanOrEqualTo(self).offset(-56);
  156. make.top.mas_equalTo(topMikeBg);
  157. make.height.mas_equalTo(topHeight);
  158. make.width.mas_equalTo(mikeLabelWidth);
  159. }];
  160. }
  161. {
  162. if (self.msgModel.showTrans && !self.msgModel.showMike) {
  163. [self.msgTransLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  164. make.left.equalTo(self.msgHeaderView.mas_right).offset(8);
  165. make.right.mas_lessThanOrEqualTo(self).offset(-56);
  166. make.top.equalTo(self.messageLabelBgView.mas_bottom).offset(8);
  167. }];
  168. [self.msgTransLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  169. make.top.left.equalTo(self.msgTransLabelBgView).offset(10);
  170. make.right.bottom.equalTo(self.msgTransLabelBgView).offset(-12);
  171. }];
  172. self.msgTransLabel.text = msgModel.sendTextTrans;
  173. }
  174. }
  175. [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
  176. make.left.mas_equalTo(8);
  177. make.top.mas_equalTo(topTimeHeight);
  178. make.width.height.mas_equalTo(48);
  179. }];
  180. }else {
  181. // self.messageLabel.textAlignment = NSTextAlignmentRight;
  182. self.messageLabel.textColor = [UIColor whiteColor];
  183. self.mikeLabel.textColor = [UIColor whiteColor];
  184. self.mikeLabelBgView.backgroundColor = SLColor(@"#448AF7");
  185. self.messageLabelBgView.backgroundColor = SLColor(@"#448AF7");
  186. self.mikeImageView.image = ImageName(@"icon_msg_yy_w");
  187. if (msgModel.onBroadcast) {
  188. self.mikeImageView.image = [SLDecodeGifImage SharedInstance].msgYyAw;
  189. [self.mikeImageView startAnimating];
  190. }
  191. NSString *headUrl = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, [SLGlobalInfo SharedInstance].loginInfo.user.userHead];
  192. [self.msgHeaderView sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:ImageName(@"icon_ellipse")];
  193. NSInteger timeLong = ceil(msgModel.audioDuration);
  194. self.mikeLabel.text = [NSString stringWithFormat:@"%ld″",timeLong];
  195. {
  196. if (!msgModel.showText) {
  197. [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  198. make.top.left.equalTo(self.messageLabelBgView).offset(10);
  199. // make.right.bottom.equalTo(self.messageLabelBgView).offset(-10);
  200. }];
  201. [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  202. make.right.equalTo(self.msgHeaderView.mas_left).offset(-8);
  203. make.left.mas_greaterThanOrEqualTo(56);
  204. make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
  205. make.height.mas_lessThanOrEqualTo(0.01);
  206. }];
  207. }else {
  208. [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  209. make.right.equalTo(self.msgHeaderView.mas_left).offset(-8);
  210. make.left.mas_greaterThanOrEqualTo(56);
  211. make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
  212. }];
  213. [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  214. make.top.left.equalTo(self.messageLabelBgView).offset(10);
  215. make.right.bottom.equalTo(self.messageLabelBgView).offset(-10);
  216. }];
  217. }
  218. }
  219. {
  220. [self.mikeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  221. make.centerY.equalTo(self.mikeLabelBgView);
  222. make.right.equalTo(self.mikeImageView.mas_left);
  223. }];
  224. [self.mikeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  225. make.centerY.equalTo(self.mikeLabelBgView);
  226. make.right.equalTo(self.mikeLabelBgView.mas_right).offset(-12);
  227. }];
  228. CGFloat mikeLabelWidth = 70.0f;
  229. if (timeLong > 0) {
  230. mikeLabelWidth = mikeLabelWidth + log(timeLong) * log(timeLong) * log(timeLong) * 4;
  231. mikeLabelWidth = MIN(kSCREEN_WIDTH * 3 / 5.0, mikeLabelWidth);
  232. // NSLog(@"--%f--%f--%f--%f--%f--%f--%f--%f--%f--%f",log(1),log(2),log(5),log(10),log(20),log(30),log(40),log(50),log(100),mikeLabelWidth);
  233. }
  234. [self.mikeLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  235. make.right.equalTo(self.msgHeaderView.mas_left).offset(-8);
  236. make.left.mas_greaterThanOrEqualTo(self).offset(56);
  237. make.top.mas_equalTo(topMikeBg);
  238. make.height.mas_equalTo(topHeight);
  239. make.width.mas_equalTo(mikeLabelWidth);
  240. }];
  241. if (msgModel.sendFailure) {
  242. if (topHeight) {
  243. [self.sendFailImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  244. make.centerY.equalTo(self.mikeLabelBgView);
  245. make.right.equalTo(self.mikeLabelBgView.mas_left).offset(-2);
  246. make.width.height.mas_equalTo(20);
  247. }];
  248. }else {
  249. [self.sendFailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  250. make.centerY.equalTo(self.messageLabelBgView);
  251. make.right.equalTo(self.messageLabelBgView.mas_left).offset(-2);
  252. make.width.height.mas_equalTo(20);
  253. }];
  254. }
  255. }
  256. }
  257. {
  258. [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
  259. make.right.mas_equalTo(-8);
  260. make.top.mas_equalTo(topTimeHeight);
  261. make.width.height.mas_equalTo(48);
  262. }];
  263. }
  264. }
  265. }
  266. - (void)setCellLayerCornerRadiusWith:(MessageModel *)msgModel {
  267. [self setNeedsLayout];
  268. [self layoutIfNeeded];
  269. // Drawing code
  270. CGFloat cornerRadius = 12;
  271. //设置所需的圆角位置以及大小
  272. UIBezierPath *maskPath;
  273. UIBezierPath *maskPath1;
  274. UIBezierPath *maskPath2;
  275. if (msgModel.isReceive) {
  276. maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageLabelBgView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
  277. maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.mikeLabelBgView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
  278. maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.msgTransLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
  279. }else {
  280. maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
  281. maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.mikeLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
  282. }
  283. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  284. maskLayer.frame = self.messageLabelBgView.bounds;
  285. maskLayer.path = maskPath.CGPath;
  286. self.messageLabelBgView.layer.mask = maskLayer;
  287. CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
  288. maskLayer1.frame = self.mikeLabelBgView.bounds;
  289. maskLayer1.path = maskPath1.CGPath;
  290. self.mikeLabelBgView.layer.mask = maskLayer1;
  291. CAShapeLayer *maskLayer2 = [[CAShapeLayer alloc] init];
  292. maskLayer2.frame = self.msgTransLabelBgView.bounds;
  293. maskLayer2.path = maskPath2.CGPath;
  294. self.msgTransLabelBgView.layer.mask = maskLayer2;
  295. }
  296. - (void)drawRect:(CGRect)rect
  297. {
  298. }
  299. - (void)mikeHandleTap:(UITapGestureRecognizer *)tap {
  300. SLMikeSegmentModel *model = [SLMikeSegmentModel initWithSegTitle:@"播放" segImage:@"icon_mike_translate" mikeType:SLMikeInputBroadcast];
  301. if (self.segmentBlock) {
  302. self.segmentBlock(model,self.msgModel);
  303. }
  304. }
  305. - (void)mikeHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
  306. if (paramSender.state == UIGestureRecognizerStateBegan) {
  307. [self showMsgSegmentWith:self.mikeLabelBgView];
  308. }
  309. }
  310. - (void)msgHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
  311. if (paramSender.state == UIGestureRecognizerStateBegan) {
  312. [self showMsgSegmentWith:self.messageLabelBgView];
  313. }
  314. }
  315. - (void)msgTransHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
  316. if (paramSender.state == UIGestureRecognizerStateBegan) {
  317. [self showMsgSegmentWith:self.msgTransLabelBgView];
  318. }
  319. }
  320. - (void)showMsgSegmentWith:(UIView *)bgView {
  321. UIViewController *vc = self.viewController;
  322. if ([vc isKindOfClass:SLMessageViewController.class]) {
  323. CGRect rect = [self convertRect:bgView.frame toView:self.viewController.view];
  324. //加一个蒙层
  325. __block UIView *bView = [[UIView alloc] initWithFrame:vc.view.frame];
  326. bView.backgroundColor = [UIColor clearColor];
  327. bView.tag = SLMikeSegMentBgTag;
  328. [vc.view addSubview:bView];
  329. NSMutableArray *arr = [NSMutableArray new];
  330. if (self.msgModel.showMike && !self.msgModel.showText) {
  331. [arr addObjectsFromArray:@[
  332. [SLMikeSegmentModel initWithSegTitle:@"查看" segImage:@"icon_eyes_on" mikeType:SLMikeInputLook],
  333. [SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]]];
  334. if (self.msgModel.isReceive) {
  335. [arr insertObject:[SLMikeSegmentModel initWithSegTitle:@"翻译" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:1];
  336. }
  337. }else if (!self.msgModel.showMike && self.msgModel.showText) {
  338. if (self.msgModel.isReceive && !self.msgModel.showTrans) {
  339. [arr insertObject:[SLMikeSegmentModel initWithSegTitle: @"翻译" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:0];
  340. }
  341. if (self.msgModel.isReceive) {
  342. [arr insertObject:[SLMikeSegmentModel initWithSegTitle: @"播放" segImage:@"icon_filled_talk" mikeType:SLMikeInputBroadcast] atIndex:0];
  343. }
  344. [arr addObjectsFromArray:@[[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy],
  345. [SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]]];
  346. }else if (self.msgModel.showMike && self.msgModel.showText) {
  347. if (bgView == self.mikeLabelBgView) {
  348. [arr addObject:[SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]];
  349. if (self.msgModel.isReceive) {
  350. [arr insertObject:[SLMikeSegmentModel initWithSegTitle:!self.msgModel.showTrans ? @"翻译" : @"原文" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:0];
  351. }
  352. }
  353. if (bgView == self.messageLabelBgView) {
  354. [arr addObject:[SLMikeSegmentModel initWithSegTitle:@"隐藏" segImage:@"icon_mike_eyes_off" mikeType:SLMikeInputHidden]];
  355. [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy]];
  356. }
  357. }
  358. if (self.msgModel.showTrans && bgView == self.msgTransLabelBgView) {
  359. [arr removeAllObjects];
  360. [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy]];
  361. [arr addObject:[SLMikeSegmentModel initWithSegTitle:@"隐藏" segImage:@"icon_mike_eyes_off" mikeType:SLMikeInputTransHidden]];
  362. }
  363. CGFloat width = arr.count * 45 + 20;
  364. CGFloat x = self.msgModel.isReceive ? rect.origin.x : rect.origin.x + rect.size.width - width;
  365. SLMikeSegment *mikeSegment = [[SLMikeSegment alloc] initWithFrame:CGRectMake(x, rect.origin.y - 59, width, 50) titleArray:arr];
  366. WS(weakSelf);
  367. mikeSegment.mikeSegmentBlock = ^(SLMikeSegmentModel *model) {
  368. [bView removeFromSuperview];
  369. if (weakSelf.segmentBlock) {
  370. weakSelf.segmentBlock(model,self.msgModel);
  371. }
  372. };
  373. [bView addSubview:mikeSegment];
  374. SLMessageViewController *msgVc = (SLMessageViewController *)vc;
  375. msgVc.hiddenMikeSegment = YES;
  376. UIImageView *imgView = [[UIImageView alloc] initWithImage:ImageName(@"icon_dsjx")];
  377. [bView addSubview:imgView];
  378. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  379. make.centerX.equalTo(mikeSegment);
  380. make.top.equalTo(mikeSegment.mas_bottom).offset(0);
  381. make.width.mas_equalTo(16);
  382. make.height.mas_equalTo(8);
  383. }];
  384. }
  385. }
  386. - (UILabel *)messageLabel
  387. {
  388. if (!_messageLabel) {
  389. _messageLabel = [[UILabel alloc] init];
  390. _messageLabel.textAlignment = NSTextAlignmentLeft;
  391. _messageLabel.numberOfLines = 0;
  392. _messageLabel.textColor = [UIColor whiteColor];
  393. _messageLabel.font = [UIFont systemFontOfSize:17];
  394. _messageLabel.userInteractionEnabled = YES;
  395. [self.messageLabelBgView addSubview:_messageLabel];
  396. }
  397. return _messageLabel;
  398. }
  399. - (UIView *)messageLabelBgView
  400. {
  401. if (!_messageLabelBgView) {
  402. _messageLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
  403. _messageLabelBgView.backgroundColor = SLColor(@"#448AF7");
  404. _messageLabelBgView.clipsToBounds = YES;
  405. _messageLabelBgView.userInteractionEnabled = YES;
  406. UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(msgHandleLongPressGestures:)];
  407. gesture.minimumPressDuration= 0.5f;
  408. [_messageLabelBgView addGestureRecognizer:gesture];
  409. [self.contentView addSubview:_messageLabelBgView];
  410. }
  411. return _messageLabelBgView;
  412. }
  413. - (UILabel *)msgTransLabel
  414. {
  415. if (!_msgTransLabel) {
  416. _msgTransLabel = [[UILabel alloc] init];
  417. _msgTransLabel.textAlignment = NSTextAlignmentLeft;
  418. _msgTransLabel.numberOfLines = 0;
  419. _msgTransLabel.textColor = [UIColor blackColor];
  420. _msgTransLabel.font = [UIFont systemFontOfSize:17];
  421. _msgTransLabel.userInteractionEnabled = YES;
  422. [self.msgTransLabelBgView addSubview:_msgTransLabel];
  423. }
  424. return _msgTransLabel;
  425. }
  426. - (UIView *)msgTransLabelBgView
  427. {
  428. if (!_msgTransLabelBgView) {
  429. _msgTransLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
  430. _msgTransLabelBgView.backgroundColor = [UIColor whiteColor];
  431. _msgTransLabelBgView.clipsToBounds = YES;
  432. _msgTransLabelBgView.userInteractionEnabled = YES;
  433. UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(msgTransHandleLongPressGestures:)];
  434. gesture.minimumPressDuration= 0.5f;
  435. [_msgTransLabelBgView addGestureRecognizer:gesture];
  436. [self.contentView addSubview:_msgTransLabelBgView];
  437. }
  438. return _msgTransLabelBgView;
  439. }
  440. //如何学习ChatGPT开发
  441. - (UIImageView *)msgHeaderView {
  442. if (!_msgHeaderView) {
  443. _msgHeaderView = [[UIImageView alloc] initWithFrame:CGRectZero];
  444. _msgHeaderView.image = ImageName(@"icon_ellipse");
  445. _msgHeaderView.layer.cornerRadius = 24.0f;
  446. _msgHeaderView.contentMode = UIViewContentModeScaleAspectFill;
  447. _msgHeaderView.clipsToBounds = YES;
  448. [self.contentView addSubview:_msgHeaderView];
  449. }
  450. return _msgHeaderView;
  451. }
  452. - (UIView *)mikeLabelBgView {
  453. if (!_mikeLabelBgView) {
  454. _mikeLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
  455. _mikeLabelBgView.backgroundColor = SLColor(@"#448AF7");
  456. _mikeLabelBgView.clipsToBounds = YES;
  457. UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(mikeHandleLongPressGestures:)];
  458. gesture.minimumPressDuration= 0.5f;
  459. [_mikeLabelBgView addGestureRecognizer:gesture];
  460. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mikeHandleTap:)];
  461. [_mikeLabelBgView addGestureRecognizer:tap];
  462. [self.contentView addSubview:_mikeLabelBgView];
  463. }
  464. return _mikeLabelBgView;
  465. }
  466. - (UIImageView *)mikeImageView {
  467. if (!_mikeImageView) {
  468. _mikeImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  469. _mikeImageView.image = ImageName(@"icon_msg_yy");
  470. _mikeImageView.userInteractionEnabled = YES;
  471. [self.mikeLabelBgView addSubview:_mikeImageView];
  472. }
  473. return _mikeImageView;
  474. }
  475. - (UILabel *)mikeLabel
  476. {
  477. if (!_mikeLabel) {
  478. _mikeLabel = [[UILabel alloc] init];
  479. _mikeLabel.text = @"30″";
  480. _mikeLabel.textAlignment = NSTextAlignmentRight;
  481. _mikeLabel.numberOfLines = 0;
  482. _mikeLabel.textColor = [UIColor whiteColor];
  483. _mikeLabel.font = [UIFont systemFontOfSize:17];
  484. _mikeLabel.userInteractionEnabled = YES;
  485. [self.mikeLabelBgView addSubview:_mikeLabel];
  486. }
  487. return _mikeLabel;
  488. }
  489. - (UILabel *)timeLabel {
  490. if (!_timeLabel) {
  491. _timeLabel = [[UILabel alloc] init];
  492. _timeLabel.textAlignment = NSTextAlignmentCenter;
  493. _timeLabel.textColor = [UIColor colorFormString:@"#3C3C43"];
  494. _timeLabel.font = [UIFont systemFontOfSize:11];
  495. [self.contentView addSubview:_timeLabel];
  496. }
  497. return _timeLabel;
  498. }
  499. - (UIImageView *)sendFailImageView {
  500. if (!_sendFailImageView) {
  501. _sendFailImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  502. _sendFailImageView.image = ImageName(@"icon_sendFail");
  503. WS(weakSelf);
  504. [_sendFailImageView addTapWithBlock:^{
  505. SLMikeSegmentModel *model = [SLMikeSegmentModel initWithSegTitle:@"重发" segImage:@"" mikeType:SLMsgRepeat];
  506. if (weakSelf.segmentBlock) {
  507. weakSelf.segmentBlock(model,self.messageLabel);
  508. }
  509. }];
  510. [self.contentView addSubview:_sendFailImageView];
  511. }
  512. return _sendFailImageView;
  513. }
  514. @end