textView自动适应高度没有闪跳(tableViewcell)

有时候textView在表单里面输入,就要有高度自适应,那该怎么处理呢

解决方法:

CGRect frame = textView.frame;

CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);

CGSize size = [textView sizeThatFits:constraintSize];

NSInteger length = size.height;

NSInteger lines = length / kFont(14).lineHeight;

NSInteger targetlines = (self.height - 38) / kFont(14).lineHeight;//38 == textView.frame.origin.x

if(targetlines != lines){

CGRect rect = textView.frame;

rect.size = size;

textView.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, size.height);

if(self.selectBlock){

self.selectBlock(rect.size.height);

}

}

//block回调

[xx setSelectBlock:^(CGFloat height){

@strongify_self;

//[self.viewModel writeSummaryCellHeight:height+38 index:index];

[self.tableView beginUpdates];

[self.tableView endUpdates];

}];

你可能感兴趣的:(textView自动适应高度没有闪跳(tableViewcell))