- (void)textViewDidChange:(UITextView *)textView
{
[textView flashScrollIndicators]; // 闪动滚动条
static CGFloat maxHeight = 130.0f;
CGRect frame = textView.frame;
CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);
CGSize size = [textView sizeThatFits:constraintSize];
if (size.height >= maxHeight)
{
size.height = maxHeight;
textView.scrollEnabled = YES; // 允许滚动
}
else
{
textView.scrollEnabled = NO; // 不允许滚动,当textview的大小足以容纳它的text的时候,需要设置scrollEnabed为NO,否则会出现光标乱滚动的情况
}
textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
}