// // YOUPAILCDynamicContentView.m // LiveChat // // Created by 张灿 on 2018/9/7. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCDynamicContentView.h" #import "YOUPAILCDynamicCell.h" #import "YBIBVideoData.h" #import #define MarginPadding (15.0f) #define IsiPhoneXr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO) @interface YOUPAILCDynamicContentView() @property(nonatomic,strong)UITextView* youpaipcontTextV; @property(nonatomic,assign)CGFloat youpaiptxtH; @end @implementation YOUPAILCDynamicContentView - (instancetype)initWithModel:(YOUPAILCDynamicModel*)model{ if (self = [super init]) { self.userInteractionEnabled = YES; self.youpaipdyModel = model; [self youpaifsetupView]; } return self; } - (instancetype)initWithFrame:(CGRect)frame model:(YOUPAILCDynamicModel*)model{ if (self = [super initWithFrame:frame]) { self.youpaipdyModel = model; [self youpaifsetupView]; } return self; } - (void)youpaifsetupView{ UITextView* contTextView = [[UITextView alloc]initWithFrame:CGRectMake(MarginPadding, 0, KScreenWidth- MarginPadding - 14.0f,120)]; //适配暗黑模式 v1.5.6 [contTextView setBackgroundColor:[UIColor clearColor]]; contTextView.scrollEnabled = NO; NSInteger textFont; if (IsiPhoneXr) { textFont = 15; }else{ textFont = 14; } // contTextView.backgroundColor = [UIColor redColor]; // contTextView.userInteractionEnabled = YES; // contTextView.numberOfLines = 0; // contTextView.lineBreakMode = NSLineBreakByWordWrapping; contTextView.textColor = LZ273145Color; contTextView.font = [UIFont systemFontOfSize:14]; contTextView.text = nil; contTextView.text = self.youpaipdyModel.youpaipcontent; contTextView.editable = NO; // contTextView.layer.masksToBounds = YES; self.youpaipcontTextV = contTextView; [self addSubview:contTextView]; CGSize constraint = CGSizeMake(contTextView.contentSize.width, CGFLOAT_MAX); // CGSize size = [self.dyModel.content sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping]; CGRect rect = [self.youpaipdyModel.youpaipcontent boundingRectWithSize:constraint options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:textFont], NSForegroundColorAttributeName : LCTextBlack } context:nil]; CGFloat textH = rect.size.height + 18.0; self.youpaiptxtH = textH; if (textH<=120) { contTextView.frame = CGRectMake(MarginPadding, 0, KScreenWidth- MarginPadding- 14.0f, textH); self.youpaipcontHeight = textH; }else{ contTextView.frame = CGRectMake(MarginPadding, 0, KScreenWidth- MarginPadding - 14.0f, 120); self.youpaipcontHeight = 115; self.youpaipcontBtn = [[UIButton alloc]initWithFrame:CGRectMake(MarginPadding, self.youpaipcontHeight, 70, 30)]; self.youpaipcontBtn.titleLabel.font = LCBoldFont(15); [self.youpaipcontBtn setTitle:@"全文" forState:(UIControlStateNormal)]; [self.youpaipcontBtn setTitleColor:LCYellowColor forState:(UIControlStateNormal)]; self.youpaipcontBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 25); self.youpaipcontBtn.titleLabel.textAlignment = NSTextAlignmentLeft; [self.youpaipcontBtn setEnlargeEdge:5]; [self addSubview:self.youpaipcontBtn]; self.youpaipcontHeight+=40; } if (self.youpaipdyModel.youpaiptype == 1) { [self youpaifsetupVideo]; }else{ if (self.youpaipdyModel.youpaipimages.count>0) { self.youpaipimgViewArray = [NSMutableArray array]; [self youpaifsetupImages]; } } } -(void)youpaifsetupVideo{ UIImageView* imgView = [[UIImageView alloc]initWithFrame:CGRectMake(MarginPadding, self.youpaipcontHeight, ScaleSize(213.0f), ScaleSize(284.0f))]; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.layer.cornerRadius = 10.0; imgView.layer.masksToBounds = YES; imgView.tag = 0; // [imgView sd_setImageWithURL:[NSURL URLWithString:self.youpaipdyModel.youpaipcover_url] placeholderImage:nil]; YOUPAILCImageModel* imgModel = self.youpaipdyModel.youpaipimages.firstObject; NSURL *url = [LCTools getImageUrlWithAddress:imgModel.youpaipurl]; if(url){ [self videoImageWithvideoURL:url completion:^(UIImage *image) { // 主线程执行: dispatch_async(dispatch_get_main_queue(), ^{ [imgView setImage:image]; }); }]; } [self addSubview:imgView]; UITapGestureRecognizer* imgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifdidClickPlayVideo:)]; imgView.userInteractionEnabled = YES; imgView.multipleTouchEnabled = YES; [imgView addGestureRecognizer:imgTap]; //播放按钮 UIImageView *playImageView = [UIImageView new]; [imgView addSubview:playImageView]; [playImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(0); make.size.mas_equalTo(CGSizeMake(52, 52)); }]; // playImageView.userInteractionEnabled = YES; playImageView.image = [UIImage imageNamed:@"vqu_images_D_dynamic_play"]; playImageView.layer.shadowColor = LCBkgColor.CGColor;//阴影颜色 playImageView.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离 playImageView.layer.shadowOpacity = 0.5;//不透明度 playImageView.layer.shadowRadius = 10.0;//半径 self.youpaipcontHeight += imgView.frame.size.height;//+10; } - (void)youpaifsetupImages{ NSArray* imgArray = self.youpaipdyModel.youpaipimages; if (imgArray.count==1) { YOUPAILCImageModel* imgModel = self.youpaipdyModel.youpaipimages[0]; CGFloat imgWidth = ScaleSize(213.0f), imgHeight = ScaleSize(284.0f); UIImageView* imgView = [[UIImageView alloc]initWithFrame:CGRectMake(MarginPadding, self.youpaipcontHeight, imgWidth, imgHeight)]; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.layer.cornerRadius = 10.0; imgView.layer.masksToBounds = YES; imgView.tag = 0; [imgView sd_setImageWithURL:[LCTools getImageUrlWithAddress:imgModel.youpaipurl] placeholderImage:nil]; [self addSubview:imgView]; UITapGestureRecognizer* imgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifimgTapHandel:)]; imgView.userInteractionEnabled = YES; imgView.multipleTouchEnabled = YES; [imgView addGestureRecognizer:imgTap]; UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflpGR:)]; //设定最小的长按时间 按不够这个时间不响应手势 longPressGR.minimumPressDuration=0.7; [imgView addGestureRecognizer:longPressGR]; self.youpaipcontHeight += imgView.frame.size.height;//+10; [self.youpaipimgViewArray addObject:imgView]; }else if(imgArray.count==4 || imgArray.count==2){ CGFloat maxWidth = KScreenWidth - MarginPadding - 14.0f; CGFloat width = maxWidth / 2; CGFloat wh = width - 3.0f; for (int i =0 ; i0) { NSMutableArray *tempArr = [NSMutableArray array]; for (int i=0; i