UITableViewCell 中的 UITextView 平滑自动调整大小 [英] UITextView in a UITableViewCell smooth auto-resize

查看:14
本文介绍了UITableViewCell 中的 UITextView 平滑自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableViewCell 内容视图中有一个 UITextView 并允许单元格自动调整大小,以便完全显示输入的文本 - 当您输入注释"时,我想要完成的是一个自动调整大小的单元格,就像本机 iOS4 联系人应用程序一样对于联系人 - 即当 textView 的 contentSize 发生变化时 - 我调用 reloadRowsAtIndexPaths 并在委托的 heightForRowAtIndexPath 中为行提供新高度 - 这可以完成工作,但是它不像联系人的应用程序那样漂亮和流畅 - 我几乎可以肯定 Apple在该应用程序中使用了一些未记录的技巧来使单元格的 contentView 扩展平滑和动画,而无需调用 reloadRowsAtIndexPaths.我的问题是你会建议如何实现这样的功能?我希望我在解释中没有遗漏任何细节.

I have a UITextView in a UITableViewCell contentview and allow the cell to autoresize so that the entered text is fully shown - what I am trying to accomplish is an autoresizing cell like the native iOS4 Contacts app has, when you enter "notes" for contact - i.e. when the contentSize of the textView changes - I call reloadRowsAtIndexPaths and in the delegate's heightForRowAtIndexPath I provide the new height for row - this does the job, however it is not nice and smooth like the contact's app - I am almost sure Apple uses some undocumented trick in that app to make the cell's contentView expand smooth and animated without calling reloadRowsAtIndexPaths. My question is how would you suggest to implement such functionality? I hope I didn't miss any details in explanation.

推荐答案

试试下面这段代码,会有帮助的.您不必使用任何重新加载函数,例如 reloadRowsAtIndexPaths.

Try this code below, it will be help. You don't have to use any reload functions like reloadRowsAtIndexPaths.

//文本视图委托

- (void)textViewDidChange:(UITextView *)textView {
    if (contentView.contentSize.height > contentRowHeight) {

    contentRowHeight = contentView.contentSize.height;

    [theTableView beginUpdates];
    [theTableView endUpdates];

    [contentView setFrame:CGRectMake(0, 0, 300.0, contentView.contentSize.height)];
    }
}

//表视图委托

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height;

    if (indexPath.row == 0)
        height = kTitleRowHeight;
    else 
        height = contentRowHeight;

    return height;
}

这篇关于UITableViewCell 中的 UITextView 平滑自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆