// // YOUPAILCMultiImageContentView.m // LiveChat // // Created by 张灿 on 2018/9/22. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCMultiImageContentView.h" #import "YOUPAILCMultiImageAttachment.h" @interface YOUPAILCMultiImageContentView() @property(nonatomic,strong)UIView* backView; @property(nonatomic,strong)UIImageView* imgView; @property(nonatomic,assign)CGFloat currentY; @end @implementation YOUPAILCMultiImageContentView - (instancetype)initSessionMessageContentView{ self = [super initSessionMessageContentView]; if (self) { self.opaque = YES; UIView* testView = [[UIView alloc] initWithFrame:CGRectZero]; testView.backgroundColor= [UIColor whiteColor]; testView.layer.cornerRadius = 6.0; testView.clipsToBounds = YES; // UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandel:)]; // [testView addGestureRecognizer:tap]; self.backView = testView; self.bubbleImageView.hidden = YES; [self addSubview:testView]; } return self; } - (void)refresh:(NIMMessageModel *)data{ [super refresh:data]; NIMCustomObject *customObject = (NIMCustomObject*)data.message.messageObject; id attachment = customObject.attachment; if ([attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]]) { for (UIView* subView in self.backView.subviews) { [subView removeFromSuperview]; } YOUPAILCMultiImageAttachment* attachment = (YOUPAILCMultiImageAttachment*)customObject.attachment; if (attachment.imageArray.count>0) { self.currentY = (KScreenWidth-30)*9/16; UIImageView* imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-30, (KScreenWidth-30)*9/16)]; imgView.backgroundColor = LCGray; imgView.userInteractionEnabled = YES; UITapGestureRecognizer* imgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgTalHandel:)]; [imgView addGestureRecognizer:imgTap]; self.imgView = imgView; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:imgView size:CGSizeMake(6, 6)]; imgView.layer.masksToBounds = YES; NSDictionary* topDict = attachment.imageArray[0]; [self.backView addSubview:imgView]; [self.imgView sd_setImageWithURL:[NSURL URLWithString:[topDict objectForKey:@"image"]]]; UIView *bottomBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, (KScreenWidth-30)*9/16-60, KScreenWidth-30, 60)]; CAGradientLayer *gradientLayerBot = [CAGradientLayer layer]; gradientLayerBot.frame = bottomBkgView.bounds; gradientLayerBot.colors = @[(__bridge id)HexColorFromRGBA(0x00000, 0.001).CGColor,(__bridge id)HexColorFromRGBA(0x000000, 0.2).CGColor]; gradientLayerBot.startPoint = CGPointMake(0, 0); gradientLayerBot.endPoint = CGPointMake(0, 1); [bottomBkgView.layer addSublayer:gradientLayerBot]; [imgView addSubview:bottomBkgView]; UILabel* titLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-70, 60)]; titLabel.textColor = [UIColor whiteColor]; titLabel.textAlignment = NSTextAlignmentLeft; titLabel.font = LCBoldFont(18); titLabel.numberOfLines=2; titLabel.text = [topDict objectForKey:@"title"]; [bottomBkgView addSubview:titLabel]; for (int i= 1; i