当我在键盘上键入返回键时如何增加文本视图的高度?
请给我解决方案。顶部有很多观点。 需要我设置所有视图的框架或只是降低表视图的高度我会得到解决方案吗?
答案 0 :(得分:1)
好吧,每当你点击键盘上的'Enter'时,你必须调整UITextView
的大小(高度),并相应调整UITableView
的大小(高度)。
答案 1 :(得分:1)
尝试使用此代码,它将根据文本内容设置TextView的高度。
[txtAddress setFrame:CGRectMake(20, 90, 280, [self contentSizeRectForTextView:txtAddress])];
TextView高度的方法:
- (CGFloat)contentSizeRectForTextView:(UITextView *)txtView
{
[txtView.layoutManager ensureLayoutForTextContainer:txtView.textContainer];
CGRect textBounds = [txtView.layoutManager usedRectForTextContainer:txtView.textContainer];
CGFloat height = (CGFloat)ceil(textBounds.size.height + txtView.textContainerInset.top + txtView.textContainerInset.bottom);
return height;
}
答案 2 :(得分:0)
设置新的帧大小时,视图框原点应该仍然相同,但帧高。
[textView setFrame: CGRectMake(textView.frame.origin.x,textView.frame.origin.y,textVie.frame.size.width,<new height>)];