UITextView in a UITableViewCell smooth auto-resize(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 平滑自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell 中的 UITextView 平滑自动调整大小


基础教程推荐
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01