我已经使用 UITextView 进行聊天,就像这里附上的截图一样。
但问题是,如果我按下键盘的返回键,光标不会停留在 UITextView 边界的底部。我还使用了以下代码:
- (void)textViewDidChange:(UITextView *)textView
{
if([textView contentSize].height <80.0)
{
CGFloat textHeight = [self textHeightForTextView:textView];
CGFloat newViewHeight = MAX(MIN(textHeight, 80.0), 33.0);
chatTxtHeightConstraint.constant = newViewHeight;
[textView scrollRangeToVisible:textView.selectedRange];
}
}
有什么解决办法吗?
最佳答案
我通过编写 [textView layoutIfNeeded];
和 [textView updateConstraints];
解决了 chatTxtHeightConstraint.constant = newViewHeight;
的代码行>
- (void)textViewDidChange:(UITextView *)textView
{
if([textView contentSize].height <80.0)
{
CGFloat textHeight = [self textHeightForTextView:textView];
CGFloat newViewHeight = MAX(MIN(textHeight, 80.0), 33.0);
chatTxtHeightConstraint.constant = newViewHeight;
[textView layoutIfNeeded];
[textView updateConstraints];
[textView scrollRangeToVisible:textView.selectedRange];
}
}
关于ios - UITextView 光标/滚动移动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030110/