gpt4 book ai didi

ios - UITextView 光标/滚动移动问题

转载 作者:行者123 更新时间:2023-11-29 12:12:26 48 4
gpt4 key购买 nike

我已经使用 UITextView 进行聊天,就像这里附上的截图一样。 enter image description here

但问题是,如果我按下键盘的返回键,光标不会停留在 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/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com