YOUPAILCDynamicCell.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // YOUPAILCDynamicCell.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/7.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCDynamicCell.h"
  9. #import "YOUPAILCDynamicHeadView.h"
  10. #import "YOUPAILCDynamicContentView.h"
  11. #import "YOUPAILCDynamicFootView.h"
  12. @interface YOUPAILCDynamicCell()<LCDynamicContentViewDelegate>
  13. @property(nonatomic,strong)YOUPAILCDynamicHeadView* youpaipheadView;
  14. @property(nonatomic,strong)YOUPAILCDynamicContentView* youpaipcontView;
  15. @property(nonatomic,strong)YOUPAILCDynamicFootView* youpaipfootView;
  16. @property(nonatomic,strong)UIView* youpaippadView;
  17. @end
  18. @implementation YOUPAILCDynamicCell
  19. +(CGFloat)youpaifcellHeightWithModel:(YOUPAILCDynamicModel*)model{
  20. YOUPAILCDynamicCell* cell = [[YOUPAILCDynamicCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"YOUPAILCDynamicCell"];
  21. // cell.dynamicModel = model;
  22. // [cell.contentView layoutIfNeeded];
  23. YOUPAILCDynamicContentView* contView = [[YOUPAILCDynamicContentView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 200) model:model];
  24. contView.userInteractionEnabled = YES;
  25. [contView.youpaipcontBtn addTarget:self action:@selector(youpaifcontBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  26. if (model.youpaipisFold==1) {
  27. [contView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)];
  28. [contView vqf_youpaifupdateTextHeight];
  29. }
  30. cell.youpaipcellHeight = contView.youpaipcontHeight+60+50;
  31. return cell.youpaipcellHeight;
  32. }
  33. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  34. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  35. self.selectionStyle = UITableViewCellSelectionStyleNone;
  36. self.backgroundColor = [UIColor clearColor];
  37. self.userInteractionEnabled = YES;
  38. self.layer.masksToBounds = YES;
  39. [self initUI];
  40. }
  41. return self;
  42. }
  43. - (void)initUI{
  44. }
  45. - (void)setYoupaipdynamicModel:(YOUPAILCDynamicModel *)dynamicModel{
  46. _youpaipdynamicModel = dynamicModel;
  47. YOUPAILCDynamicHeadView* headView = [[YOUPAILCDynamicHeadView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,60) model:dynamicModel];
  48. // [headView.youpaipmoreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  49. [headView.siliaoBtn addTarget:self action:@selector(youpaifimChatClick) forControlEvents:(UIControlEventTouchUpInside)];
  50. UITapGestureRecognizer* avatarTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifavatarHandel:)];
  51. headView.youpaipavatarImgV.userInteractionEnabled = YES;
  52. [headView.youpaipavatarImgV addGestureRecognizer:avatarTap];
  53. [self.contentView addSubview:headView];
  54. self.youpaipheadView = headView;
  55. self.youpaipcellHeight = 60;
  56. YOUPAILCDynamicContentView* contView = [[YOUPAILCDynamicContentView alloc]initWithFrame:CGRectMake(0, self.youpaipcellHeight, KScreenWidth, 180) model:dynamicModel];
  57. contView.userInteractionEnabled = YES;
  58. contView.layer.masksToBounds = YES;
  59. contView.youpaipdelegate = self;
  60. [contView.youpaipcontBtn addTarget:self action:@selector(youpaifcontBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  61. self.youpaipcontView = contView;
  62. [self.contentView addSubview:contView];
  63. if (self.youpaipdynamicModel.youpaipisFold==1) {
  64. [self.youpaipcontView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)];
  65. [self.youpaipcontView vqf_youpaifupdateTextHeight];
  66. }
  67. self.youpaipcontView.frame = CGRectMake(0, 60, KScreenWidth, self.youpaipcontView.youpaipcontHeight);
  68. self.youpaipcellHeight+= contView.youpaipcontHeight;
  69. YOUPAILCDynamicFootView* footView = [[YOUPAILCDynamicFootView alloc]initWithFrame:CGRectMake(0, self.youpaipcellHeight, KScreenWidth,50) model:dynamicModel];
  70. /*
  71. [footView.rewardBtn setTitle:[NSString stringWithFormat:@"赠送 %zd",dynamicModel.reward_count] forState:(UIControlStateNormal)];
  72. [footView.rewardBtn addTarget:self action:@selector(youpaifrewardClick) forControlEvents:(UIControlEventTouchUpInside)];
  73. */
  74. [footView.youpaipvideoBtn addTarget:self action:@selector(youpaifimVideoClick) forControlEvents:UIControlEventTouchUpInside];
  75. [footView.youpaipimBtn addTarget:self action:@selector(youpaifimChatClick) forControlEvents:UIControlEventTouchUpInside];
  76. [footView.youpaipattentionBtn addTarget:self action:@selector(youpaifattentionBtnClick) forControlEvents:UIControlEventTouchUpInside];
  77. // [footView.youpaipsendGiftBtn addTarget:self action:@selector(youpaifsendGiftBtnClick) forControlEvents:UIControlEventTouchUpInside];
  78. [footView.youpaipmoreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  79. [self.contentView addSubview:footView];
  80. self.youpaipfootView = footView;
  81. self.youpaipcellHeight+= 50;
  82. // UIView* padView = [[UIView alloc]initWithFrame:CGRectMake(0, self.cellHeight, KScreenWidth, 10)];
  83. // padView.backgroundColor = LCBkgColor;
  84. // [self.contentView addSubview:padView];
  85. // self.padView = padView;
  86. // self.cellHeight+=10;
  87. [self.contentView setBackgroundColor:[UIColor clearColor]];
  88. self.contentView.userInteractionEnabled = YES;
  89. }
  90. //送礼
  91. -(void)youpaifsendGiftBtnClick{
  92. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaiffootViewdidSendGift:)]) {
  93. [self.youpaipdelegate youpaiffootViewdidSendGift:self.youpaipdynamicModel];
  94. }
  95. }
  96. -(void)youpaifimChatClick
  97. {
  98. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickImChat:)]) {
  99. [self.youpaipdelegate youpaifclickImChat:self.youpaipdynamicModel];
  100. }
  101. }
  102. -(void)youpaifattentionBtnClick
  103. {
  104. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickAttention:)]) {
  105. [self.youpaipdelegate youpaifclickAttention:self.youpaipdynamicModel];
  106. }
  107. }
  108. -(void)youpaifimVideoClick
  109. {
  110. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickImVideo:)]) {
  111. [self.youpaipdelegate youpaifclickImVideo:self.youpaipdynamicModel];
  112. }
  113. }
  114. - (void)youpaifrewardClick{
  115. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickReward:)]) {
  116. [self.youpaipdelegate youpaifclickReward:self.youpaipdynamicModel];
  117. }
  118. }
  119. - (void)youpaifmoreBtnClick{
  120. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickMoreBtn:index:)]) {
  121. [self.youpaipdelegate youpaifclickMoreBtn:self.youpaipdynamicModel index:self.youpaipcurrentIndex];
  122. }
  123. }
  124. - (void)youpaifavatarHandel:(UITapGestureRecognizer*)tap{
  125. if (tap.state == UIGestureRecognizerStateEnded) {
  126. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifclickAvatar:)]) {
  127. [self.youpaipdelegate youpaifclickAvatar:self.youpaipdynamicModel];
  128. }
  129. }
  130. }
  131. - (void)youpaifcontBtnClick{
  132. if ([self.youpaipcontView.youpaipcontBtn.titleLabel.text isEqualToString:@"全文"]) {
  133. self.youpaipdynamicModel.youpaipisFold = 1;
  134. [self.youpaipcontView.youpaipcontBtn setTitle:@"收起" forState:(UIControlStateNormal)];
  135. [self.youpaipcontView vqf_youpaifupdateTextHeight];
  136. [self vqf_youpaifneedUpdateHeight];
  137. }else{
  138. self.youpaipdynamicModel.youpaipisFold = 0;
  139. [self.youpaipcontView.youpaipcontBtn setTitle:@"全文" forState:(UIControlStateNormal)];
  140. [self.youpaipcontView vqf_youpaifupdateTextHeight];
  141. [self vqf_youpaifneedUpdateHeight];
  142. }
  143. }
  144. - (void)vqf_youpaifneedUpdateHeight{
  145. self.youpaipcellHeight = self.youpaipcontView.youpaipcontHeight+60+60;
  146. self.youpaipheadView.frame = CGRectMake(0, 0, KScreenWidth, 60);
  147. self.youpaipcontView.frame = CGRectMake(0, 60, KScreenWidth, self.youpaipcontView.youpaipcontHeight);
  148. self.youpaipfootView.frame = CGRectMake(0, self.youpaipcontView.youpaipcontHeight+60, KScreenWidth, 50);
  149. self.youpaippadView.frame = CGRectMake(0, self.youpaipcontView.youpaipcontHeight+60+50, KScreenWidth, 10);
  150. self.youpaipcellHeight = self.youpaipcontView.youpaipcontHeight+60+60;
  151. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifneedUpdateCellHeight:cell:)]) {
  152. [self.youpaipdelegate youpaifneedUpdateCellHeight:self.youpaipcurrentIndex cell:self];
  153. }
  154. }
  155. -(void)youpaifdidPlayVideo:(YOUPAILCDynamicModel *)model{
  156. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifCelldidPlayVideo:)]) {
  157. [self.youpaipdelegate youpaifCelldidPlayVideo:model];
  158. }
  159. }
  160. -(void)youpaifdeleteImage:(YOUPAILCDynamicModel *)model
  161. {
  162. if (self.youpaipdelegate && [self.youpaipdelegate respondsToSelector:@selector(youpaifdeleteImage:index:)]) {
  163. [self.youpaipdelegate youpaifdeleteImage:model index:self.youpaipcurrentIndex];
  164. }
  165. }
  166. @end