本文介绍了在滚动时有效地调整UITableViewCell的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总体思路

我希望在用户滚动列表时动态调整UITableViewCells的大小,也就是说,使项目到达列表底部时,其大小会不断增加.

Im looking to resize UITableViewCells dynamically as the user scrolls the list, to say, make the items grow in size as they reach the bottom of the list.

注意事项

此过程需要在每秒调用一次的情况下刷新多次:

This is a process that needs to be refreshed multiple times per second as a call is made to:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

因此,采用 UITableView :: ReloadData 方法来调用以下代码是不切实际的:

So it is impractical to take the UITableView::ReloadData approach so that a call is made to:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

因为这将需要重新加载一堆额外的数据并极大地减慢系统速度.

Since this will need to reload a bunch of extra data and slow down the system immensely.

需求

  • 我将在屏幕上显示大约10个项目.
  • 在极端情况下,整个清单可能最多包含100个项目.
  • 系统需要平滑滚动.
  • 项目需要随着列表滚动而实时平滑地平滑扩展和收缩.
  • I will have at around 10 items on screen.
  • entire list might have up to 100 items on extrem cases.
  • Systems needs to scroll smoothly.
  • Items need to expand and contract smoothly in real time as list scrolls.

常识

  • 与带有静态项目的列表相比,这肯定会对性能产生影响.

  • This will definitely have some performance impact vs a list with static items.

有数百个线程处理简单的将cel调整为文本长度"的情况,这不是我所需要的,因为与之相比,这是一次性的事情,每秒有很多周期.p>

There are hundreds of threads dealing with the simple case of "resize cel to text length" which is not what I need, as that is a one time thing compared to this with lots of cycles per second.

可能的方法

  • 子类 UITableView .
  • UIScrollView 中嵌套了一个静态的 UITableView .
  • 从头开始创建项目列表系统,完全不使用 UIScrollView .
  • Subclass UITableView.
  • Have a static UITableView nested in a UIScrollView.
  • Create an item list system from scratch and not use UIScrollView at all.

废弃的方法

  • 每个周期调用 UITableView :: ReloadData ,以便调用 heightForRowAtIndexPath :.
  • Call UITableView::ReloadData per cycle so that heightForRowAtIndexPath: is called.

到目前为止

我已经编写了一个模块,该模块可以计算项目大小的数学值.

I've already coded a module that calculates the math for item size.

结论

我正在寻找解决此问题的最快方法,但如果需要,我将重新编码自己的 UITableView .

I'm looking for the quickest way to solved this but I will recode my own UITableView if needed as a last resort.

感谢您的时间.

推荐答案

在使用 UITableView 进行了严格的测试之后,我还没有找到一种有效地做到这一点的方法.似乎 UITableView 可能以不允许动态调整单元格大小的方式进行了优化.因此,制作自定义清单系统似乎是唯一的选择.我已经开始在 UIScrollView 之上进行此类项目构建.

After heavy testing with UITableView I have not found a way to do this efficiently. It seems that UITableView might be optimized in a way that does not permit dynamic cell resizing. For this reason making a custom listing system seems to be the only option. I have begun work on such project building on top of UIScrollView.

大部分基本功能都已完成,但是由于我目前有一个更重要的系统需要开发,因此该项目目前处于暂停状态.如果您有兴趣参加这个项目,请告诉我.

A large part of the basic functionality is complete but the project is currently on hold as I have a more important system to develop as of present. If you are interested in taking part in this project let me know.

这篇关于在滚动时有效地调整UITableViewCell的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:21
查看更多