123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // 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<attachment.imageArray.count; i++) {
- NSDictionary* dict = attachment.imageArray[i];
- UIButton* btn = [[UIButton alloc]initWithFrame:CGRectMake(0, self.currentY, KScreenWidth-30, 100)];
- btn.backgroundColor = HexColorFromRGB(0x2A2935);
- btn.adjustsImageWhenHighlighted = NO;
- btn.tag = i;
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:(UIControlEventTouchUpInside)];
-
- UIImageView* imgView = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-30-20-72, 18, 72, 72)];
- imgView.backgroundColor = LCGray;
- imgView.layer.masksToBounds = YES;
- [imgView sd_setImageWithURL:[NSURL URLWithString:[dict objectForKey:@"image"]]];
- [btn addSubview:imgView];
-
- UILabel* titLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 18, KScreenWidth-30-20-72-40, 72)];
- titLabel.textColor = [UIColor whiteColor];
- titLabel.textAlignment = NSTextAlignmentLeft;
- titLabel.font = LCBoldFont(18);
- titLabel.numberOfLines=2;
- titLabel.text = [dict objectForKey:@"title"];
- [btn addSubview:titLabel];
-
- if (i!=attachment.imageArray.count-1) {
- UIView* lineV = [[UIView alloc]initWithFrame:CGRectMake(20, 99.5, KScreenWidth-30-20-72-40, 0.5)];
- lineV.backgroundColor = HexColorFromRGB(0xe6e6e6);
- [btn addSubview:lineV];
- }
- [self.backView addSubview:btn];
- self.currentY+=100;
- }
-
- }else{
- self.currentY = 0;
-
- }
- }
- }
- - (void)btnClick:(UIButton*)btn{
- NIMKitEvent *event = [[NIMKitEvent alloc] init];
- event.eventName = NIMKitEventNameTapContent;
- event.messageModel = self.model;
- event.messageModel.message.localExt = @{
- @"serial":@(btn.tag)
- };
- [self.delegate onCatchEvent:event];
- }
- - (void)imgTalHandel:(UITapGestureRecognizer*)tap{
- if (tap.state == UIGestureRecognizerStateEnded) {
- NIMKitEvent *event = [[NIMKitEvent alloc] init];
- event.eventName = NIMKitEventNameTapContent;
- event.messageModel = self.model;
- event.messageModel.message.localExt = @{
- @"serial":@(0)
- };
- [self.delegate onCatchEvent:event];
- }
- }
- - (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)layoutSubviews{
- [super layoutSubviews];
- UIEdgeInsets contentInsets = self.model.contentViewInsets;
- // CGFloat tableViewWidth = self.superview.nim_width;
- CGSize contentsize = [self.model contentSize:KScreenWidth];
- CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
- self.backView.frame = imageViewFrame;
-
- }
- @end
|