ContentTableViewCell.m 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  ContentTableViewCell.m
//  Lighting
//
//  Created by 曹云霄 on 2016/12/9.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ContentTableViewCell.h"
#import "STEmojiKeyboard.h"

@implementation ContentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
Sandy's avatar
Sandy committed
16

17 18 19 20
    [self setUpToolView];
}

#pragma mark - ToolView
Sandy's avatar
Sandy committed
21
- (void)setUpToolView {
22 23 24
    KeyBoardAccessoryView *toolView = [[KeyBoardAccessoryView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    toolView.delegate = self;
    self.contentTextView.inputAccessoryView = toolView;
25
    self.contentTextView.m_placeHolder = @"请输入内容";
26 27 28
}

#pragma mark - Click
Sandy's avatar
Sandy committed
29
- (void)extensionButtonClick:(UIButton *)sender {
30
    switch (sender.tag) {
Sandy's avatar
Sandy committed
31
        case Camera: {
32 33 34
            if ([self.delgate respondsToSelector:@selector(showCameraAction)]) {
                [self.delgate showCameraAction];
            }
Sandy's avatar
Sandy committed
35 36
        } break;
        case PhotoAlbum: {
37 38 39
            if ([self.delgate respondsToSelector:@selector(showPhotoAlbumAction)]) {
                [self.delgate showPhotoAlbumAction];
            }
Sandy's avatar
Sandy committed
40 41
        } break;
        case Emoji: {
42 43 44
            sender.selected = !sender.selected;
            if (sender.selected) {
                [[STEmojiKeyboard keyboard] setTextView:self.contentTextView];
Sandy's avatar
Sandy committed
45
            } else {
46 47 48 49 50
                [self.contentTextView setInputView:nil];
            }
            [self.contentTextView reloadInputViews];
            [self.contentTextView becomeFirstResponder];

Sandy's avatar
Sandy committed
51 52
        } break;

53 54 55 56 57 58
        default:
            break;
    }
}

#pragma mark - <UITextViewDelegate>
Sandy's avatar
Sandy committed
59
- (void)textViewDidEndEditing:(UITextView *)textView {
60
    self.heightConstraint.constant = [self calculateStudyIntroductionHeight:textView.text];
61 62 63 64 65 66
    if ([self.delgate respondsToSelector:@selector(refreshHeight:)]) {
        [self.delgate refreshHeight:self.contentTextView.height];
    }
}

#pragma mark - 计算高度
Sandy's avatar
Sandy committed
67 68
- (CGFloat)calculateStudyIntroductionHeight:(NSString *)content {
    return [content heightWithFontSize:14 width:ScreenWidth - 40] + 20;
69 70 71 72
}


@end