Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions InputView/YZInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ - (UITextView *)placeholderView

- (void)awakeFromNib
{
[super awakeFromNib];
[self setup];
}

Expand All @@ -69,6 +70,7 @@ - (void)setup
self.layer.cornerRadius = 5;
self.layer.borderColor = [UIColor lightGrayColor].CGColor;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self];
[self addObserver:self forKeyPath:@"text" options:(NSKeyValueObservingOptionNew) context:nil];
}

- (void)setMaxNumberOfLines:(NSUInteger)maxNumberOfLines
Expand Down Expand Up @@ -129,9 +131,16 @@ - (void)textDidChange
}
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"text"] && !self.isFirstResponder) {
[self textDidChange];
}
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeObserver:self forKeyPath:@"text"];
}

@end
6 changes: 6 additions & 0 deletions YZInputViewDemo/YZInputViewDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ - (void)viewDidLoad {
_inputView.maxNumberOfLines = 4;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//test
_inputView.text = @"Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test,Hello This is test";
}

// 键盘弹出会调用
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
Expand Down