|
//
// otherPersonContentCell.m
// ThePaperBase
//
// Created by YoungLee on 15/11/24.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "otherPersonContentCell.h"
@implementation otherPersonContentCell
@synthesize commentBO = _commentBO;
@synthesize frontComment = _frontComment;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.lineView.hidden = YES;
self.expandBtn.hidden = YES;
[self subLayoutSubViews];
}
return self;
}
- (void)setCommentBO:(commentObjectVO *)data {
_commentBO = data;
self.aswerContentLabel.text = _commentBO.content;
[self reLayoutSubViews];
}
-(void)setFrontComment:(commentObjectVO *)comment{
_frontComment = comment;
if ([_frontComment.type intValue] == 2) {
self.menuButton.hidden = YES;
}else{
self.menuButton.hidden = NO;
}
}
#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.frontComment];
};
}
- (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);
}];
}
- (void)reLayoutSubViews {
__weak typeof(self) weakSelf = self;
CGFloat answerContentHeight = self.commentBO.labelHeight;
[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).offset(10);
make.height.mas_equalTo(answerContentHeight);
}];
}
@end
|