UITableView将行锚定到底部 [英] UITableView anchor rows to bottom

查看:102
本文介绍了UITableView将行锚定到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要从底部引入新内容的UITableView。这是表视图在视图已满时的行为方式,并且您添加了带动画的新行。

I have a UITableView that needs to introduce new content from the bottom. This is how a table view behaves when the view is full and you add new rows with animation.

我是通过在引入行时更改contentInset来启动它,但是当时他们改变了事情,并且输入动画都是错误的...这种方法的问题更加复杂,因为用户可以删除行,行内容更新,导致它们调整大小(每行都有自己的高度,更改)。

I was starting it by altering the contentInset as rows are introduced but then when they change things go off, and the entry animation is all wrong... My problem with this approach is compounded by the fact that users can delete rows, and the row contents update, causing them to resize (each row has it's own height which changes).

有关如何将UITableView行始终显示在UITableView视图空间底部的任何建议?

Any recommendations on how to get a UITableView rows to always appear at the bottom of the UITableView's view space?

推荐答案

我有一个完美适合我的解决方案,但它引起了一堆双重思考,所以它在理论上并不像在实践中那么简单......有点儿...

I've got a solution that works for me perfectly, but it causes a bunch of double thinking so it's not as simple in theory as it is in practice... kinda...

步骤1,将变换应用于表格视图,将其旋转180度

Step 1, apply a transform to the table view rotating it 180deg

tableView.transform = CGAffineTransformMakeRotation(-M_PI);

步骤2,在tableView中旋转原始单元格180deg:cellForRowAtIndexPath:

Step 2, rotate your raw cell 180deg in tableView:cellForRowAtIndexPath:

cell.transform = CGAffineTransformMakeRotation(M_PI);

步骤3,反转您的数据源。如果您正在使用NSMutableArray在位置0处插入新对象而不是使用AddObject ...

Step 3, reverse your datasource. If you're using an NSMutableArray insert new objects at location 0 instead of using AddObject...

现在,困难的部分是记住左边是右边还是左边只在表级,所以如果你使用

Now, the hard part is remembering that left is right and right is left only at the table level, so if you use

[tableView insertRowsAtIndexPaths:targetPath withRowAnimation:UITableViewRowAnimationLeft]

现在必须

[tableView insertRowsAtIndexPaths:targetPath withRowAnimation:UITableViewRowAnimationRight]

和删除等相同。

根据您的数据存储,您可能需要按相反的顺序处理...

Depending on what your data store is you may have to handle that in reverse order as well...

注意:旋转表格中的单元格OPPOSITE,否则浮点空洞可能会导致变换完美,并且当你滚动时,你会不时地抓住某些图形......轻微但很烦人。

Note: rotate the cells OPPOSITE the table, otherwise floating point innacuracy might cause the transform to get off perfect and you'll get crawlies on some graphics from time to time as you scroll... minor but annoying.

这篇关于UITableView将行锚定到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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