如何在UITableView行之间创建工具栏 [英] How to create a toolbar between UITableView rows
问题描述
我对tweetbot如何执行以下操作感兴趣:
I am interested on how tweetbot does the following:
我想用我的应用程序创建相同的东西,如果你点击一行,它会弹出
an额外的UIToolBar并按下任何其他行将使用动画关闭此视图。
I would like to create the same thing with my app, where if you click on a row, it pops an additional UIToolBar and pressing on any other row will dismiss this view with animations.
我认为逻辑很简单,只需要在按下时向UITableViewCell添加一个子视图将剩下的内容移动起来,但是当我按下另一行时你怎么实际忽略它?
The logic I think is simple, you just need to add a subView to the UITableViewCell when pressed and shift the rest of the content up, but how do you actually dismiss it when I press the other row?
推荐答案
在 tableView:didSelectRowAtIndexPath:
,从最后选择的单元格中删除工具视图。如果没有这样的视图,则创建一个新视图。然后将此视图添加到新选择的单元格。保存所选行的indexPath。
In tableView:didSelectRowAtIndexPath:
, you remove the tool view from the last selected cell. If there is no such view, you create a new one. Then you add this view to the newly selected cell. Save the indexPath of the selected row.
在 tableView:heightForRowAtIndexPath:
中,检查indexPath是否相同作为已保存的indexPath。如果它们相等,则返回高度,即两个视图的高度。如果它不相等,只需返回真实单元格的高度。
In tableView:heightForRowAtIndexPath:
, you check if the indexPath is the same as the saved indexPath. If they are equal, you return a height that is the height of both views. If it is not equal, just return the height of the "real cell".
将所有调用放入 didSelectRowAtIndexPath
在 [tableView beginUpdates]
和 [tableView endUpdates]
之间获取高度变化的动画。
Put all your calls in didSelectRowAtIndexPath
between [tableView beginUpdates]
and [tableView endUpdates]
to get animation for the height change.
这篇关于如何在UITableView行之间创建工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!