Repository navigation
Expand file tree
/
Copy pathSMNoteDetailView.m
More file actions
166 lines (131 loc) · 4.41 KB
/
Copy pathSMNoteDetailView.m
File metadata and controls
166 lines (131 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// SMNoteDetailView.m
// SMNote
//
// Created by SimonMiao on 16/8/11.
// Copyright © 2016年 MSY. All rights reserved.
//
#import "SMNoteDetailView.h"
#import <Masonry/Masonry.h>
#import "ATTextView.h"
#import "SMNoteDetailBottomToolBar.h"
#import "SMNoteDetailModel.h"
#import "NSString+ATConverter.h"
@interface SMNoteDetailView () <UITextViewDelegate>
{
NSDate *_currentDate;
}
@property (nonatomic, strong) UILabel *dateLab;
@property (nonatomic, strong) ATTextView *textView;
@property (nonatomic, strong) SMNoteDetailBottomToolBar *toolBar;
@end
@implementation SMNoteDetailView
- (instancetype)init
{
self = [super init];
if (self) {
[self addSubview:self.textView];
[self.textView addSubview:self.dateLab];
[self addSubview:self.toolBar];
self.textView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);;
self.textView.scrollEnabled = YES;
[self initConstraints];
}
return self;
}
- (void)initConstraints {
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self);
make.bottom.mas_equalTo(self.toolBar.mas_top).mas_offset(- 10);
}];
[self.dateLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.textView).offset(- 20);
make.centerX.mas_equalTo(self.textView);
make.height.mas_equalTo(20);
}];
[self.toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.right.mas_equalTo(self);
make.height.mas_equalTo(44);
}];
}
- (void)setDetailModel:(SMNoteDetailModel *)detailModel {
if (!detailModel) {
return;
}
_detailModel = detailModel;
self.textView.text = detailModel.contentStr;
self.dateLab.text = [NSString at_getFormatterDateStrWithFormatterStr:@"yyyy年MM月dd日 HH:mm" timeStamp:detailModel.timestamp];
}
//注销键盘
- (void)resignKeyboard
{
[self.textView resignFirstResponder];
if ([_delegate respondsToSelector:@selector(smNoteDetailViewDelegateOfResignFirstResponder:)]) {
SMNoteDetailModel *model = [self coverTheModel];
[_delegate smNoteDetailViewDelegateOfResignFirstResponder:model];
}
}
- (SMNoteDetailModel *)coverTheModel {
if (_detailModel) {
_detailModel.contentStr = self.textView.text;
return _detailModel;
} else {
SMNoteDetailModel *model = [[SMNoteDetailModel alloc] init];
model.contentStr = self.textView.text;
NSTimeInterval timeInterval = [_currentDate timeIntervalSince1970];
model.timestamp = [NSNumber numberWithDouble:timeInterval];
model.image = nil;
return model;
}
}
#pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
// [self moveUpTextViewFrame];
if ([_delegate respondsToSelector:@selector(smNoteDetailViewDelegateOfBecomeFirstResponder)]) {
[_delegate smNoteDetailViewDelegateOfBecomeFirstResponder];
}
return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
// _remark = textView.text;
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
ATLog(@"scrollViewWillBeginDragging");
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
ATLog(@"是否减速:%i",decelerate);
if (scrollView.contentOffset.y < 0 && decelerate) {
[self resignKeyboard];
} else {
}
}
- (UILabel *)dateLab {
if (!_dateLab) {
_currentDate = [NSDate date];
NSString *dateStr = [NSString at_getFormatterDateStrWithFormatterStr:@"yyyy年MM月dd日 HH:mm" date:_currentDate];
_dateLab = [UILabel at_createLabWithText:dateStr fontSize:10.0 titleColor:[UIColor lightGrayColor]];
}
return _dateLab;
}
- (ATTextView *)textView {
if (!_textView) {
_textView = [[ATTextView alloc] init];
_textView.editable = YES;
_textView.delegate = self;
_textView.textColor = [UIColor at_blackColor];
_textView.font = [UIFont systemFontOfSize:13.0];
_textView.placeholderColor = [UIColor at_lightGrayColor];
_textView.placeholder = @"填写note...";
}
return _textView;
}
- (SMNoteDetailBottomToolBar *)toolBar {
if (!_toolBar) {
_toolBar = [[SMNoteDetailBottomToolBar alloc] init];
}
return _toolBar;
}
@end