我需要创建两个文本输入字段,一个在另一个下面。当用户在上部文本字段中键入内容时,我需要动态增加框架大小(不建议在 TextView 内滚动。)并且下部文本输入框架应向下。这在ios上可以实现吗?任何帮助将不胜感激。
最佳答案
您可以通过其 contentSize 更新 textView 的框架,如下所示:
-(void)updateTextViewSize
{
CGRect rect = textView.frame;
rect.size.width = textView.contentSize.width;
rect.size.height = textView.contentSize.height;
textView.frame = rect;
//lowering the textView2 below this textView
//assuming that the lower textview touches the
//bottom of the upper textView.
CGRect rect2 = textViewLower.frame;
rect2.origin.y = textView.frame.origin.y + textView.frame.size.height;
textViewLower.frame = rect2;
//update your scrollView here
//assuming textView and textViewLower are already added to the scrollView
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, textViewLower.frame.origin.y + textViewLower.frame.size.height);
}
//implement this delegate method as shown below
-(void)textViewDidChange:(UITextView*)textView
{
[self updateTextViewSize];
}
关于ios - 如何在用户键入时创建增加框架大小而不是增加滚动大小的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655376/