【发布时间】:2010-02-22 18:45:28
【问题描述】:
我想将一行移动到我的UITableView 的底部,具有酷炫的动画效果,就像在this Grocery Shopping List app 中一样。
就像我们可以使用重新排序控件移动行一样:
如何制作这样的动画?
【问题讨论】:
标签: iphone cocoa-touch uitableview animation core-animation
我想将一行移动到我的UITableView 的底部,具有酷炫的动画效果,就像在this Grocery Shopping List app 中一样。
就像我们可以使用重新排序控件移动行一样:
如何制作这样的动画?
【问题讨论】:
标签: iphone cocoa-touch uitableview animation core-animation
在 IOS 5 中,这可以通过以下 UITableView 选择器来完成:
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
例如:
[self.tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:[items count] - 1 inSection:1]];
【讨论】:
重要提示:此答案假定 iPhone OS 3.x。 See the answer above 适用于 iOS 5.x
我不知道什么是“酷炫的动画效果就像在杂货购物清单应用程序中一样”。不是每个人都有那个应用程序。
无法以编程方式移动行。
但是,您可以同时插入和删除一行来模拟移动。
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:rowToMove]
withRowAnimation:UITableViewRowAnimationLeft];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToMoveTo]
withRowAnimation:UITableViewRowAnimationLeft];
// update your dataSource as well.
[tableView endUpdates];
【讨论】:
这有点类似于我所做的允许从一个滚动视图拖放到另一个滚动视图。
您将要创建一个重复/虚拟单元格(为了视觉效果),然后删除原始单元格,然后为副本设置动画,然后插入底部,最后删除重复/虚拟单元格。
【讨论】: