// // YOUPAILCGiftContentView.m // LiveChat // // Created by 张灿 on 2018/9/22. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCGiftContentView.h" #import "YOUPAILCGiftAttachment.h" @interface YOUPAILCGiftContentView() @property(nonatomic,strong)UIView* backView; @property(nonatomic,strong)UILabel* topTitle; @property(nonatomic,strong)UIImageView* iconImgView; @property(nonatomic,strong)UILabel* contentLabel; @end @implementation YOUPAILCGiftContentView - (instancetype)initSessionMessageContentView{ self = [super initSessionMessageContentView]; if (self) { // self.opaque = YES; // UIImageView* testView = [[UIImageView alloc] initWithFrame:CGRectZero]; // testView.backgroundColor= [UIColor whiteColor]; // testView.contentMode = UIViewContentModeScaleAspectFill; // testView.layer.cornerRadius = 6.0; // testView.userInteractionEnabled = YES; // UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)]; // [testView addGestureRecognizer:tap]; UIView *backView = [[UIView alloc] init]; UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)]; [backView addGestureRecognizer:tap]; self.backView = backView; self.bubbleImageView.hidden = YES; [self addSubview:backView]; } return self; } - (void)refresh:(NIMMessageModel *)data{ [super refresh:data]; NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject; id attachment = customObject.attachment; if ([attachment isKindOfClass:[YOUPAILCGiftAttachment class]]) { for (UIView* subview in self.backView.subviews) { [subview removeFromSuperview]; } YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)customObject.attachment; UIView *textBgV = [[UIView alloc] init]; [self.backView addSubview:textBgV]; UILabel *titleL = [[UILabel alloc] init]; titleL.textColor = LZ273145Color; titleL.font = LCBoldFont(14.0f); if (data.message.isOutgoingMsg) { titleL.text = @"送出礼物"; }else{ titleL.text = @"收到礼物"; } [textBgV addSubview:titleL]; UILabel *giftL = [[UILabel alloc] init]; giftL.textColor = LZ7C69FEColor; giftL.font = LCFont(11.0f); giftL.text = [NSString stringWithFormat:@"%@x%@",attachment.gift_name,@(attachment.gift_count)]; [textBgV addSubview:giftL]; UIImageView *giftBgImgV = [[UIImageView alloc] init]; if (data.message.isOutgoingMsg) { giftBgImgV.image = [UIImage imageNamed:@"vqu_images_im_gift_right"]; }else{ giftBgImgV.image = [UIImage imageNamed:@"vqu_images_im_gift_left"]; } [self.backView addSubview:giftBgImgV]; UIImageView *giftImgV = [[UIImageView alloc] init]; giftImgV.contentMode = UIViewContentModeScaleAspectFill; giftImgV.image = [LCTools giftImgWithGiftUrlStr:attachment.gift_url]; [giftBgImgV addSubview:giftImgV]; if (data.message.isOutgoingMsg) { [giftBgImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(0.0f); make.centerY.equalTo(self.backView); make.size.mas_offset(CGSizeMake(88.0f, 77.0f)); }]; [textBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.backView); make.left.equalTo(giftBgImgV.mas_right).offset(8.0f); // make.right.offset(0.0f); }]; [giftImgV mas_remakeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(giftBgImgV); make.left.offset(10.0f); make.size.mas_offset(CGSizeMake(57.0f, 57.0f)); }]; }else{ [textBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(0.0f); make.centerY.equalTo(self.backView); }]; [giftBgImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(textBgV.mas_right).offset(8.0f); make.centerY.equalTo(self.backView); make.size.mas_offset(CGSizeMake(88.0f, 77.0f)); // make.right.offset(0.0f); }]; [giftImgV mas_remakeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(giftBgImgV); make.right.offset(-10.0f); make.size.mas_offset(CGSizeMake(57.0f, 57.0f)); }]; } [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); }]; [giftL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(titleL.mas_bottom).offset(8.0f); make.left.right.bottom.offset(0.0f); }]; } } - (void)tapHandel:(UITapGestureRecognizer*)tap{ // if (tap.state == UIGestureRecognizerStateEnded) { // NIMKitEvent *event = [[NIMKitEvent alloc] init]; // event.eventName = NIMKitEventNameTapContent; // event.messageModel = self.model; // [self.delegate onCatchEvent:event]; // } } - (void)onTouchUpInside:(id)sender { // NIMKitEvent *event = [[NIMKitEvent alloc] init]; // event.eventName = NIMKitEventNameTapContent; // event.messageModel = self.model; // [self.delegate onCatchEvent:event]; } - (void)layoutSubviews{ [super layoutSubviews]; UIEdgeInsets contentInsets = self.model.contentViewInsets; CGSize contentSize = [self.model contentSize:KScreenWidth]; CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentSize.width, contentSize.height); self.backView.frame = imageViewFrame; } @end