// // YOUPAILCDynamicCell.m // LiveChat // // Created by 张灿 on 2018/9/7. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCDynamicCell.h" #import "YOUPAILCDynamicHeadView.h" #import "YOUPAILCDynamicContentView.h" #import "YOUPAILCDynamicFootView.h" @interface YOUPAILCDynamicCell() @property(nonatomic,strong)YOUPAILCDynamicHeadView* youpaipheadView; @property(nonatomic,strong)YOUPAILCDynamicContentView* youpaipcontView; @property(nonatomic,strong)YOUPAILCDynamicFootView* youpaipfootView; @property(nonatomic,strong)UIView* youpaippadView; @end @implementation YOUPAILCDynamicCell +(CGFloat)youpaifcellHeightWithModel:(YOUPAILCDynamicModel*)model{ YOUPAILCDynamicCell* cell = [[YOUPAILCDynamicCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"YOUPAILCDynamicCell"]; // cell.dynamicModel = model; // [cell.contentView layoutIfNeeded]; YOUPAILCDynamicContentView* contView = [[YOUPAILCDynamicContentView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 200) model:model]; contView.userInteractionEnabled = YES; [contView.youpaipcontBtn addTarget:self action:@selector(youpaifcontBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; if (model.youpaipisFold==1) { [contView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)]; [contView vqf_youpaifupdateTextHeight]; } cell.youpaipcellHeight = contView.youpaipcontHeight+60+50; return cell.youpaipcellHeight; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; self.userInteractionEnabled = YES; self.layer.masksToBounds = YES; [self initUI]; } return self; } - (void)initUI{ } - (void)setYoupaipdynamicModel:(YOUPAILCDynamicModel *)dynamicModel{ _youpaipdynamicModel = dynamicModel; YOUPAILCDynamicHeadView* headView = [[YOUPAILCDynamicHeadView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,60) model:dynamicModel]; // [headView.youpaipmoreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [headView.siliaoBtn addTarget:self action:@selector(youpaifimChatClick) forControlEvents:(UIControlEventTouchUpInside)]; UITapGestureRecognizer* avatarTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifavatarHandel:)]; headView.youpaipavatarImgV.userInteractionEnabled = YES; [headView.youpaipavatarImgV addGestureRecognizer:avatarTap]; [self.contentView addSubview:headView]; self.youpaipheadView = headView; self.youpaipcellHeight = 60; YOUPAILCDynamicContentView* contView = [[YOUPAILCDynamicContentView alloc]initWithFrame:CGRectMake(0, self.youpaipcellHeight, KScreenWidth, 180) model:dynamicModel]; contView.userInteractionEnabled = YES; contView.layer.masksToBounds = YES; contView.youpaipdelegate = self; [contView.youpaipcontBtn addTarget:self action:@selector(youpaifcontBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; self.youpaipcontView = contView; [self.contentView addSubview:contView]; if (self.youpaipdynamicModel.youpaipisFold==1) { [self.youpaipcontView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)]; [self.youpaipcontView vqf_youpaifupdateTextHeight]; } self.youpaipcontView.frame = CGRectMake(0, 60, KScreenWidth, self.youpaipcontView.youpaipcontHeight); self.youpaipcellHeight+= contView.youpaipcontHeight; YOUPAILCDynamicFootView* footView = [[YOUPAILCDynamicFootView alloc]initWithFrame:CGRectMake(0, self.youpaipcellHeight, KScreenWidth,50) model:dynamicModel]; /* [footView.rewardBtn setTitle:[NSString stringWithFormat:@"赠送 %zd",dynamicModel.reward_count] forState:(UIControlStateNormal)]; [footView.rewardBtn addTarget:self action:@selector(youpaifrewardClick) forControlEvents:(UIControlEventTouchUpInside)]; */ [footView.youpaipvideoBtn addTarget:self action:@selector(youpaifimVideoClick) forControlEvents:UIControlEventTouchUpInside]; [footView.youpaipimBtn addTarget:self action:@selector(youpaifimChatClick) forControlEvents:UIControlEventTouchUpInside]; [footView.youpaipattentionBtn addTarget:self action:@selector(youpaifattentionBtnClick) forControlEvents:UIControlEventTouchUpInside]; // [footView.youpaipsendGiftBtn addTarget:self action:@selector(youpaifsendGiftBtnClick) forControlEvents:UIControlEventTouchUpInside]; [footView.youpaipmoreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [self.contentView addSubview:footView]; self.youpaipfootView = footView; self.youpaipcellHeight+= 50; // UIView* padView = [[UIView alloc]initWithFrame:CGRectMake(0, self.cellHeight, KScreenWidth, 10)]; // padView.backgroundColor = LCBkgColor; // [self.contentView addSubview:padView]; // self.padView = padView; // self.cellHeight+=10; [self.contentView setBackgroundColor:[UIColor clearColor]]; self.contentView.userInteractionEnabled = YES; } //送礼 -(void)youpaifsendGiftBtnClick{ if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaiffootViewdidSendGift:)]) { [self.youpaipdelegate youpaiffootViewdidSendGift:self.youpaipdynamicModel]; } } -(void)youpaifimChatClick { if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickImChat:)]) { [self.youpaipdelegate youpaifclickImChat:self.youpaipdynamicModel]; } } -(void)youpaifattentionBtnClick { if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickAttention:)]) { [self.youpaipdelegate youpaifclickAttention:self.youpaipdynamicModel]; } } -(void)youpaifimVideoClick { if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickImVideo:)]) { [self.youpaipdelegate youpaifclickImVideo:self.youpaipdynamicModel]; } } - (void)youpaifrewardClick{ if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickReward:)]) { [self.youpaipdelegate youpaifclickReward:self.youpaipdynamicModel]; } } - (void)youpaifmoreBtnClick{ if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickMoreBtn:index:)]) { [self.youpaipdelegate youpaifclickMoreBtn:self.youpaipdynamicModel index:self.youpaipcurrentIndex]; } } - (void)youpaifavatarHandel:(UITapGestureRecognizer*)tap{ if (tap.state == UIGestureRecognizerStateEnded) { if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickAvatar:)]) { [self.youpaipdelegate youpaifclickAvatar:self.youpaipdynamicModel]; } } } - (void)youpaifcontBtnClick{ if ([self.youpaipcontView.youpaipcontBtn.titleLabel.text isEqualToString:@"全文"]) { self.youpaipdynamicModel.youpaipisFold = 1; [self.youpaipcontView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)]; [self.youpaipcontView vqf_youpaifupdateTextHeight]; [self vqf_youpaifneedUpdateHeight]; }else{ self.youpaipdynamicModel.youpaipisFold = 0; [self.youpaipcontView.youpaipcontBtn setTitle:@"全文" forState:(UIControlStateNormal)]; [self.youpaipcontView vqf_youpaifupdateTextHeight]; [self vqf_youpaifneedUpdateHeight]; } } - (void)vqf_youpaifneedUpdateHeight{ self.youpaipcellHeight = self.youpaipcontView.youpaipcontHeight+60+60; self.youpaipheadView.frame = CGRectMake(0, 0, KScreenWidth, 60); self.youpaipcontView.frame = CGRectMake(0, 60, KScreenWidth, self.youpaipcontView.youpaipcontHeight); self.youpaipfootView.frame = CGRectMake(0, self.youpaipcontView.youpaipcontHeight+60, KScreenWidth, 50); self.youpaippadView.frame = CGRectMake(0, self.youpaipcontView.youpaipcontHeight+60+50, KScreenWidth, 10); self.youpaipcellHeight = self.youpaipcontView.youpaipcontHeight+60+60; if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifneedUpdateCellHeight:cell:)]) { [self.youpaipdelegate youpaifneedUpdateCellHeight:self.youpaipcurrentIndex cell:self]; } } -(void)youpaifdidPlayVideo:(YOUPAILCDynamicModel *)model{ if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifCelldidPlayVideo:)]) { [self.youpaipdelegate youpaifCelldidPlayVideo:model]; } } -(void)youpaifdeleteImage:(YOUPAILCDynamicModel *)model { if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifdeleteImage:index:)]) { [self.youpaipdelegate youpaifdeleteImage:model index:self.youpaipcurrentIndex]; } } @end