// // messageNoExpandCell.m // ThePaperHD // // Created by YoungLee on 15/7/31. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "messageNoExpandCell.h" @interface messageNoExpandCell() @property(nonatomic, strong)UIImageView *commentBack; @property(nonatomic, strong)UILabel *quoNameLable; //楼层用户名 @property(nonatomic, strong)UILabel *quoContentLabel; //楼层内 @property(nonatomic, strong)UIButton *ansImg; @property(nonatomic, strong)UIButton *commentBackBtn; @end @implementation messageNoExpandCell @synthesize commentBO = _commentBO; @synthesize isHaveCopyMenu = _isHaveCopyMenu; @synthesize isNeedTizhu = _isNeedTizhu; @synthesize isNeedAsImg = _isNeedAsImg; -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.clipsToBounds = YES; _isNeedTizhu = YES; self.headPicImgView.hidden = YES; self.vipImg.hidden = YES; self.expandBtn.hidden = YES; [self addSubview:self.ansImg]; [self bringSubviewToFront:self.menuButton]; self.isHaveCopyMenu = YES; } return self; } - (void)setIsHaveCopyMenu:(BOOL)menu { _isHaveCopyMenu = menu; if (menu) { self.menuButton.hidden = NO; }else { self.menuButton.hidden = YES; } } -(void)setIsNeedTizhu:(BOOL)tizhu{ _isNeedTizhu = tizhu; } -(void)setIsNeedAsImg:(BOOL)isNeed{ _isNeedAsImg = isNeed; self.ansImg.hidden = _isNeedAsImg; } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = data; if (_commentBO.quoteInfo.count > 0) { self.lineView.hidden = YES; }else{ self.lineView.hidden = NO; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]); NSString *nameStr; if([user.userId intValue] == [[TPUserDefault instance].userBO.userId intValue]){ // if([user.userId isEqualToString:[TPUserDefault instance].userBO.userId]){ nameStr = @"我:"; }else{ nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; } // NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; self.answerNameHeight = heightForString(nameStr, self.answerNameLabel.font, 400, self.answerNameLabel.lineBreakMode); // CGFloat trueContentHeight= returnTextHeightWithRTLabel(data.content, messagePopSize.width-30, appFont(interactionFontSize, NO),10); CGFloat trueContentHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO)), messagePopSize.width -30, appFont(interactionFontSize, NO)); self.answerContentHeight = trueContentHeight; NSString *praiseNum = data.praiseTimes; dispatch_async(dispatch_get_main_queue(), ^{ self.answerNameLabel.text = nameStr; // self.answerContentLabel.text = data.content; self.answerContentLabel.attributedText = getLineSpaceAttributedString(data.content, 10, appFont(interactionFontSize, NO)); if (data.quoteInfo && data.quoteInfo.allKeys.count>0) { NSDictionary *dic = data.quoteInfo; commentObjectVO *quoBO = setJsonDicToDataModel(dic, [commentObjectVO class]); self.commentBack.hidden = NO; self.quoNameLable.text = @"我:"; self.quoContentLabel.text = quoBO.content; }else { self.commentBack.hidden = YES; } self.timeLabel.text = data.pubTime; if (!isBlankString(praiseNum)) { self.praiseButton.titleText = praiseNum; } if (data.isPraised && [data.isPraised intValue] == 1) { [self.praiseButton setSelect:YES animation:NO]; self.praiseButton.userInteractionEnabled = NO; }else { [self.praiseButton setSelect:NO animation:NO]; self.praiseButton.userInteractionEnabled = YES; } [self layoutSubviews]; }); }); } #pragma mark -- view -(UIButton *)ansImg{ if (!_ansImg) { _ansImg = [UIButton buttonWithType:UIButtonTypeCustom]; [_ansImg setBackgroundImage:Image(@"detailPage/message_answer.png") forState:UIControlStateNormal]; [_ansImg setBackgroundImage:Image(@"detailPage/message_answer_h.png") forState:UIControlStateHighlighted]; [_ansImg addTarget:self action:@selector(gotoAnswer:) forControlEvents:UIControlEventTouchUpInside]; _ansImg.userInteractionEnabled = YES; } return _ansImg; } - (UIImageView*)commentBack { if (!_commentBack) { _commentBack = [[UIImageView alloc]initWithImage:Image(@"detailPage/commentBack.png")]; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _commentBack.image = Image(@"detailPage/commentBack_night.png"); } _commentBack.userInteractionEnabled = YES; } return _commentBack; } -(UIButton *)commentBackBtn{ if (!_commentBackBtn) { _commentBackBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // _commentBackBtn.backgroundColor = [UIColor greenColor]; _commentBackBtn.userInteractionEnabled = YES; [_commentBackBtn addTarget:self action:@selector(commbackExpand:) forControlEvents:UIControlEventTouchUpInside]; } return _commentBackBtn; } - (UILabel*)quoNameLable { if (!_quoNameLable) { _quoNameLable = [[UILabel alloc]initWithFrame:CGRectZero]; _quoNameLable.textColor = [UIColor colorWithHexString:BLUECOLOR]; _quoNameLable.textAlignment = NSTextAlignmentLeft; _quoNameLable.font = appFont(12,NO); _quoNameLable.backgroundColor = [UIColor clearColor]; } return _quoNameLable; } - (UILabel*)quoContentLabel { if (!_quoContentLabel) { _quoContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _quoContentLabel.textColor = [UIColor colorWithHexString:TextGray]; _quoContentLabel.textAlignment = NSTextAlignmentLeft; _quoContentLabel.numberOfLines = 2; _quoContentLabel.lineBreakMode = NSLineBreakByTruncatingTail; _quoContentLabel.font = appFont(interactionFontSize,NO); _quoContentLabel.backgroundColor = [UIColor clearColor]; } return _quoContentLabel; } - (void)layoutSubviews { [super layoutSubviews]; self.answerNameLabel.frame = CGRectMake(15,15, widthForString(self.answerNameLabel.text, self.answerNameLabel.font, self.answerNameHeight, self.answerNameLabel.lineBreakMode), self.answerNameHeight); self.timeLabel.frame = CGRectMake(CGRectGetMinX(self.answerNameLabel.frame), CGRectGetMaxY(self.answerNameLabel.frame), 100, 16); self.answerContentLabel.frame = CGRectMake(CGRectGetMinX(self.answerNameLabel.frame), CGRectGetMaxY(self.timeLabel.frame)+15, messagePopSize.width -30, self.answerContentHeight); self.lineView.frame = CGRectMake(15, CGRectGetHeight(self.bounds)-1, CGRectGetWidth(self.bounds)-30, 1); self.praiseButton.frame = CGRectMake(CGRectGetWidth(self.bounds)-40, CGRectGetMinY(self.answerNameLabel.frame), 25, 45); self.ansImg.frame = CGRectMake(CGRectGetMinX(self.praiseButton.frame)-55, CGRectGetMinY(self.praiseButton.frame)+8, 35, 37); if (!self.commentBack.hidden) { if (self.expandBtn.hidden) { self.commentBack.frame =CGRectMake(CGRectGetMinX(self.answerContentLabel.frame), CGRectGetMaxY(self.answerContentLabel.frame)+15, messagePopSize.width-30, 167/2); }else { self.commentBack.frame =CGRectMake(CGRectGetMinX(self.answerContentLabel.frame), CGRectGetMaxY(self.expandBtn.frame)+5, messagePopSize.width-30, 167/2); } self.quoNameLable.frame = CGRectMake(10, 18, CGRectGetWidth(self.commentBack.frame)-20, 20); self.quoContentLabel.frame = CGRectMake(10, CGRectGetMaxY(self.quoNameLable.frame), CGRectGetWidth(self.quoNameLable.frame), 55); [self.quoContentLabel sizeToFit]; self.menuButton.frame = self.answerContentLabel.frame; self.commentBackBtn.frame = self.commentBack.frame; }else { self.commentBack.frame = CGRectZero; self.commentBackBtn.frame = self.commentBack.frame; self.menuButton.frame = self.answerContentLabel.frame; } } #pragma mark - menu tap handler - (void)menuTap:(UITapGestureRecognizer*)tap { [self becomeFirstResponder]; UIMenuItem *commentBack = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)]; UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)]; UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"点赞"action:@selector(praise:)]; // UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"删除"action:@selector(deleteComment:)]; UIMenuController *menu = [UIMenuController sharedMenuController]; if (menu.menuVisible) { [menu setMenuVisible:NO animated:YES]; return; } NSDictionary *userInfo = self.commentBO.userInfo; userBO *user = setJsonDicToDataModel(userInfo, [userBO class]); if ([user.userId longLongValue] == [[TPUserDefault instance].userBO.userId longLongValue]) { [menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, praise,nil]]; }else { [menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, praise, nil]]; } [menu setTargetRect:self.answerContentLabel.frame inView:self]; [menu setMenuVisible:YES animated:YES]; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { [super canPerformAction:action withSender:sender]; if ( action == @selector(commentBack:) || action == @selector(copyText:) || action == @selector(praise:) || action == @selector(deleteComment:)) { return YES; } else { return NO; } } - (void)commentBack:(id)sender { if ([self.delegate respondsToSelector:@selector(answerForUserBack: closeHidden:)]) { [self.delegate answerForUserBack:self.commentBO closeHidden:YES]; } } -(void)gotoAnswer:(UIButton*)btn{ if ([self.delegate respondsToSelector:@selector(gotoAnswer:)]) { [self.delegate gotoAnswer:_commentBO]; } } -(void) commbackExpand:(UIButton *) btn{ // self.quoContentLabel.numberOfLines = 0; // self.quoNameLable.frame = CGRectMake(10, 18, CGRectGetWidth(self.commentBack.frame)-20, 20); // self.quoContentLabel.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) } @end