textView.delegate = self;
-(void)textViewDidChange:(UITextView *)textView{
static CGFloat maxHeight =60.0f;
CGRect frame = textView.frame;
CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);
CGSize size = [textView sizeThatFits:constraintSize];
if (size.height<=frame.size.height) {
size.height=frame.size.height;
}else{
if (size.height >= maxHeight)
{
size.height = maxHeight;
textView.scrollEnabled = YES; // 允许滚动
}
else
{
textView.scrollEnabled = NO; // 不允许滚动
}
}
textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
}