From 784da11b9a43d2eb3063ab1334f218316912c169 Mon Sep 17 00:00:00 2001 From: dengliwen Date: Mon, 24 Oct 2016 16:57:00 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:1.=E5=BD=93=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=5FinputView.text=E8=BF=9B=E8=A1=8C=E8=B5=8B?= =?UTF-8?q?=E5=80=BC=E6=97=B6=EF=BC=8C=E8=BF=9B=E8=A1=8C=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E3=80=82=EF=BC=88=E8=BF=90=E7=94=A8?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=EF=BC=9A=E5=A6=82=E5=8A=A0=E8=BD=BD=E4=B8=8A?= =?UTF-8?q?=E6=AC=A1=E6=9C=AA=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=EF=BC=89?= =?UTF-8?q?=202.=20missing=20[super=20awakeFromNib]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InputView/YZInputView.m | 9 +++++++++ YZInputViewDemo/YZInputViewDemo/ViewController.m | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/InputView/YZInputView.m b/InputView/YZInputView.m index 62481af..a1273d0 100644 --- a/InputView/YZInputView.m +++ b/InputView/YZInputView.m @@ -48,6 +48,7 @@ - (UITextView *)placeholderView - (void)awakeFromNib { + [super awakeFromNib]; [self setup]; } @@ -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 @@ -129,9 +131,16 @@ - (void)textDidChange } } +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([keyPath isEqualToString:@"text"] && !self.isFirstResponder) { + [self textDidChange]; + } +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + [self removeObserver:self forKeyPath:@"text"]; } @end diff --git a/YZInputViewDemo/YZInputViewDemo/ViewController.m b/YZInputViewDemo/YZInputViewDemo/ViewController.m index 482f04e..52dc9c6 100644 --- a/YZInputViewDemo/YZInputViewDemo/ViewController.m +++ b/YZInputViewDemo/YZInputViewDemo/ViewController.m @@ -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 {