【发布时间】:2015-08-18 21:38:31
【问题描述】:
我在设置UITextView 的高度时遇到问题,例如消息应用程序。它是通过在出现换行时增加它的高度来实现的。
我的问题是,当用户编辑文本内容时,它并没有降低容器的高度,其中textview 是一个孩子。
我正在使用自动布局和这段代码
- (void)textViewDidChange:(UITextView *)textView {
UITextPosition* pos = self.posttextView.endOfDocument;//explore others like beginningOfDocument if you want to customize the behaviour
CGRect currentRect = [self.posttextView caretRectForPosition:pos];
if (currentRect.origin.y > previousRect.origin.y){
if (self.containerHeightt.constant == 99) {
return;
}
self.containerHeightt.constant += 10;
NSLog(@"the container height is %f",self.containerHeightt.constant);
}
previousRect = currentRect;
}
请告诉我如何检测何时从textview 中删除了一行,然后降低容器的高度。
【问题讨论】:
-
你试过只使用文本视图的
contentSize吗? -
不,我没有那样尝试。
-
我可以在出现新行时增加容器的大小,但是当从 UITextView 中删除一行时如何减小其高度。正如我所说,我正在使用 AutoLayout
-
我的意思是使用
contentSize找出所需的高度并将其用作约束常量
标签: ios height uitextview