YOUPAILCGiftContentView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // YOUPAILCGiftContentView.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/22.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCGiftContentView.h"
  9. #import "YOUPAILCGiftAttachment.h"
  10. @interface YOUPAILCGiftContentView()
  11. @property(nonatomic,strong)UIView* backView;
  12. @property(nonatomic,strong)UILabel* topTitle;
  13. @property(nonatomic,strong)UIImageView* iconImgView;
  14. @property(nonatomic,strong)UILabel* contentLabel;
  15. @end
  16. @implementation YOUPAILCGiftContentView
  17. - (instancetype)initSessionMessageContentView{
  18. self = [super initSessionMessageContentView];
  19. if (self) {
  20. // self.opaque = YES;
  21. // UIImageView* testView = [[UIImageView alloc] initWithFrame:CGRectZero];
  22. // testView.backgroundColor= [UIColor whiteColor];
  23. // testView.contentMode = UIViewContentModeScaleAspectFill;
  24. // testView.layer.cornerRadius = 6.0;
  25. // testView.userInteractionEnabled = YES;
  26. // UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
  27. // [testView addGestureRecognizer:tap];
  28. UIView *backView = [[UIView alloc] init];
  29. UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)];
  30. [backView addGestureRecognizer:tap];
  31. self.backView = backView;
  32. self.bubbleImageView.hidden = YES;
  33. [self addSubview:backView];
  34. }
  35. return self;
  36. }
  37. - (void)refresh:(NIMMessageModel *)data{
  38. [super refresh:data];
  39. NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject;
  40. id attachment = customObject.attachment;
  41. if ([attachment isKindOfClass:[YOUPAILCGiftAttachment class]]) {
  42. for (UIView* subview in self.backView.subviews) {
  43. [subview removeFromSuperview];
  44. }
  45. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)customObject.attachment;
  46. UIView *textBgV = [[UIView alloc] init];
  47. [self.backView addSubview:textBgV];
  48. UILabel *titleL = [[UILabel alloc] init];
  49. titleL.textColor = LZ273145Color;
  50. titleL.font = LCBoldFont(14.0f);
  51. if (data.message.isOutgoingMsg) {
  52. titleL.text = @"送出礼物";
  53. }else{
  54. titleL.text = @"收到礼物";
  55. }
  56. [textBgV addSubview:titleL];
  57. UILabel *giftL = [[UILabel alloc] init];
  58. giftL.textColor = LZ7C69FEColor;
  59. giftL.font = LCFont(11.0f);
  60. giftL.text = [NSString stringWithFormat:@"%@x%@",attachment.gift_name,@(attachment.gift_count)];
  61. [textBgV addSubview:giftL];
  62. UIImageView *giftBgImgV = [[UIImageView alloc] init];
  63. if (data.message.isOutgoingMsg) {
  64. giftBgImgV.image = [UIImage imageNamed:@"vqu_images_im_gift_right"];
  65. }else{
  66. giftBgImgV.image = [UIImage imageNamed:@"vqu_images_im_gift_left"];
  67. }
  68. [self.backView addSubview:giftBgImgV];
  69. UIImageView *giftImgV = [[UIImageView alloc] init];
  70. giftImgV.contentMode = UIViewContentModeScaleAspectFill;
  71. giftImgV.image = [LCTools giftImgWithGiftUrlStr:attachment.gift_url];
  72. [giftBgImgV addSubview:giftImgV];
  73. if (data.message.isOutgoingMsg) {
  74. [giftBgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.offset(0.0f);
  76. make.centerY.equalTo(self.backView);
  77. make.size.mas_offset(CGSizeMake(88.0f, 77.0f));
  78. }];
  79. [textBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.centerY.equalTo(self.backView);
  81. make.left.equalTo(giftBgImgV.mas_right).offset(8.0f);
  82. // make.right.offset(0.0f);
  83. }];
  84. [giftImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
  85. make.centerY.equalTo(giftBgImgV);
  86. make.left.offset(10.0f);
  87. make.size.mas_offset(CGSizeMake(57.0f, 57.0f));
  88. }];
  89. }else{
  90. [textBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.offset(0.0f);
  92. make.centerY.equalTo(self.backView);
  93. }];
  94. [giftBgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.equalTo(textBgV.mas_right).offset(8.0f);
  96. make.centerY.equalTo(self.backView);
  97. make.size.mas_offset(CGSizeMake(88.0f, 77.0f));
  98. // make.right.offset(0.0f);
  99. }];
  100. [giftImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
  101. make.centerY.equalTo(giftBgImgV);
  102. make.right.offset(-10.0f);
  103. make.size.mas_offset(CGSizeMake(57.0f, 57.0f));
  104. }];
  105. }
  106. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.right.top.offset(0.0f);
  108. }];
  109. [giftL mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.top.equalTo(titleL.mas_bottom).offset(8.0f);
  111. make.left.right.bottom.offset(0.0f);
  112. }];
  113. }
  114. }
  115. - (void)tapHandel:(UITapGestureRecognizer*)tap{
  116. if (tap.state == UIGestureRecognizerStateEnded) {
  117. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  118. event.eventName = NIMKitEventNameTapContent;
  119. event.messageModel = self.model;
  120. [self.delegate onCatchEvent:event];
  121. }
  122. }
  123. - (void)onTouchUpInside:(id)sender
  124. {
  125. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  126. event.eventName = NIMKitEventNameTapContent;
  127. event.messageModel = self.model;
  128. [self.delegate onCatchEvent:event];
  129. }
  130. - (void)layoutSubviews{
  131. [super layoutSubviews];
  132. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  133. CGSize contentSize = [self.model contentSize:KScreenWidth];
  134. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentSize.width, contentSize.height);
  135. self.backView.frame = imageViewFrame;
  136. }
  137. @end