|
//
// msgAnswerContentCell.m
// ThePaperBase
//
// Created by YoungLee on 15/11/18.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "msgAnswerContentCell.h"
@implementation msgAnswerContentCell
@synthesize commentBO = _commentBO;
@synthesize cellHeight = _cellHeight;
//@synthesize expandBtn = _expandBtn;
@synthesize expandHidden = _expandHidden;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.lineView.hidden = YES;
[self.backView removeFromSuperview];
[self.contentView addSubview:self.backView];
[self subLayoutSubViews];
}
return self;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
CGFloat trueContentHeight= self.commentBO.labelHeight;
// CGFloat fourLine = (appFont(TEXT_FOUR_LEVELSIZE, NO).lineHeight + 10)*4 + 1;
CGFloat fourLine = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
if (!data.isExpand || [data.isExpand intValue] == 0) {
_cellHeight = trueContentHeight>fourLine?fourLine:trueContentHeight;
}else {
_cellHeight = trueContentHeight;
}
self.aswerContentLabel.text = data.content;
if (trueContentHeight > fourLine) {
self.expandBtn.hidden = NO;
}else self.expandBtn.hidden = YES;
if (data.quoteInfo && data.quoteInfo.allKeys.count>0) {//TODO当有图片的时候也应该隐藏线
self.lineView.hidden = YES;
}else self.lineView.hidden = NO;
if (data.imageList.count > 0) {
self.lineView.hidden = YES;
}else self.lineView.hidden = YES;
[self reLayoutSubViews];
}
-(void)setExpandHidden:(BOOL)hidden{
_expandHidden = hidden;
}
#pragma mark - menu tap handler
- (void)menuTap:(UIButton*)btn {
[self becomeFirstResponder];
UIMenuItem *commentItem = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)];
UIMenuItem *share = [[UIMenuItem alloc] initWithTitle:@"分享" action:@selector(shareTo:)];
UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"点赞"action:@selector(praise:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:commentItem,copy,share ,praise, nil]];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
[menu setTargetRect:self.aswerContentLabel.frame inView:self];
[menu setMenuVisible:YES animated:YES];
}
#pragma mark - menuDelegate
- (BOOL)canBecomeFirstResponder {
[super canBecomeFirstResponder];
return 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(shareTo:))
{
return YES;
}
else
{
return NO;
}
}
-(void) commentBack:(id) sender{
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
}
if ([self.delegate respondsToSelector:@selector(gotoCommentWith:)]) {
[self.delegate gotoCommentWith:self.commentBO];
};
}
- (void)copyText:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.aswerContentLabel.text;
ShowMessage(@"复制成功", YES);
}
- (void)praise:(UIButton *)sender {
if ([self.delegate respondsToSelector:@selector(praiseHandlerWithIndexPath:)]) {
[self.delegate praiseHandlerWithIndexPath:self.indexPath];
}
}
-(void) shareTo:(id)sender{
if ([self.delegate respondsToSelector:@selector(gotoShare:index:)]) {
[self.delegate gotoShare:self.commentBO index:self.indexPath];
}
// ShowTextMessage(@"和代码就好了");
}
- (void)subLayoutSubViews {
__weak typeof(self) weakSelf = self;
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.contentView.left).offset(10);
make.right.equalTo(weakSelf.contentView.right).offset(-10);
make.top.equalTo(weakSelf.contentView.top);
make.bottom.equalTo(weakSelf.contentView.bottom);
}];
[self.menuButton makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(weakSelf.aswerContentLabel);
}];
[self.expandBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left);
make.right.equalTo(weakSelf.backView.right);
make.top.equalTo(weakSelf.aswerContentLabel.bottom);
make.height.mas_equalTo(25);
}];
}
- (void)reLayoutSubViews {
__weak typeof(self) weakSelf = self;
// CGFloat four = (self.aswerContentLabel.font.lineHeight + self.aswerContentLabel.lineSpace)*4+self.aswerContentLabel.lineSpace/2;
CGFloat four = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
CGFloat answerContentHeight = self.commentBO.labelHeight;
if (self.expandHidden) {
self.expandBtn.hidden = YES;
}else{
if (answerContentHeight > four) {
self.expandBtn.hidden = NO;
}else self.expandBtn.hidden = YES;
if (!self.commentBO.isExpand || [self.commentBO.isExpand intValue] == 0) {
answerContentHeight = answerContentHeight>four?four:answerContentHeight;
[self.expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
}else {
[self.expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal];
}
}
[self.aswerContentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(10);
make.right.equalTo(weakSelf.backView.right).offset(-10);
make.top.equalTo(weakSelf.backView.top);
make.height.mas_equalTo(answerContentHeight);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.backView.left).offset(10);
make.right.equalTo(weakSelf.backView.right).offset(-10);
make.bottom.equalTo(weakSelf.backView.bottom);
make.height.mas_equalTo(1);
}];
}
@end
|