ios - 在自动布局中隐藏不断增长的 UItextview 的键盘。如何克服这一点?
<p><p>我需要在我的应用中实现聊天功能。其中我有一个如图所示的 InputView。</p>
<p><strong><code>图片 1</code></strong></p>
<p> <a href="/image/Ogsds.png" rel="noreferrer noopener nofollow"><img src="/image/Ogsds.png" alt="enter image description here"/></a> </p>
<p><strong><code>图片 2</code></strong></p>
<p> <a href="/image/5sykh.png" rel="noreferrer noopener nofollow"><img src="/image/5sykh.png" alt="enter image description here"/></a> . </p>
<p>InputView 是带有左右按钮和 TextView 的 <code>蓝色彩色 View </code>。 </p>
<ol>
<li>单击文本字段时,此输入 View 应向上滚动并且键盘应出现。这个 TextView 是一个不断增长的文本字段,其中包含文本数量。</li>
<li>但是当我在文本字段中输入多行时。 InputView 和 Textfield 都在增长,但它在键盘下方略微隐藏,如下所示如何克服它???</li>
</ol>
<p><strong><code>图 3</code></strong></p>
<p> <a href="/image/pXYqA.png" rel="noreferrer noopener nofollow"><img src="/image/pXYqA.png" alt="enter image description here"/></a> </p>
<p>**</p>
<blockquote>
<p>And I used this code</p>
</blockquote>
<p>**.</p>
<pre><code>-(void)viewWillAppear:(BOOL)animated{
;
;
}
- (void)viewWillDisappear:(BOOL)animated {
;
;
}
- (void)registerForKeyboardNotifications
{
[ addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[ addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[ addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardDidHideNotification object:nil];
}
- (void)deregisterFromKeyboardNotifications {
[ removeObserver:self
name:UIKeyboardDidHideNotification
object:nil];
[ removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = ;
CGSize kbSize = [ CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, self.inputView.frame.origin) ) {
;
}
;
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
;
}
- (void)textViewDidChange:(UITextView *)textView {
CGSize sizeThatShouldFitTheContent = ;
//chatView_heightConstraint is the inputview height
self.chatView_heightConstraint.constant = MIN(sizeThatShouldFitTheContent.height + 8, 87);
CGRect _f = self.textView.frame;
_f.size.height = MIN( self.textView.contentSize.height, 79.0);
self.textView.frame = _f;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>最后我解决了这个问题...在 ScrollView 之后添加了一个 View ,这个技巧奏效了!!! <code>ScrollView --> UIView --> TableView 和 InputView</code></p></p>
<p style="font-size: 20px;">关于ios - 在自动布局中隐藏不断增长的 UItextview 的键盘。如何克服这一点?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34738198/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34738198/
</a>
</p>
页:
[1]