【问题标题】:Programmaticlaly moving rows with animation in UITableView在 UITableView 中以编程方式移动带有动画的行
【发布时间】:2010-02-22 18:45:28
【问题描述】:

我想将一行移动到我的UITableView 的底部,具有酷炫的动画效果,就像在this Grocery Shopping List app 中一样。

就像我们可以使用重新排序控件移动行一样:

如何制作这样的动画?

【问题讨论】:

    标签: iphone cocoa-touch uitableview animation core-animation


    【解决方案1】:

    在 IOS 5 中,这可以通过以下 UITableView 选择器来完成:

    - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
    

    例如:

    [self.tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:[items count] - 1 inSection:1]];
    

    【讨论】:

    【解决方案2】:

    重要提示:此答案假定 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];
    

    【讨论】:

    • Kenny,我说的效果是一个落行动画,就像在重新排列模式时用手指拖动它一样。我想知道它是怎么做到的。我考虑将单元格内容绘制成半透明的uiimage,然后将带有动画的图像移动到所需的位置,但我不确定这是最好的解决方案
    • 您找到解决方案了吗?我有一个类似的问题:stackoverflow.com/questions/5112588/… & stackoverflow.com/questions/5315990/…
    • 也许你只需要将RowAnimation效果改为:UITableViewRowAnimationBottom
    【解决方案3】:

    这有点类似于我所做的允许从一个滚动视图拖放到另一个滚动视图。

    您将要创建一个重复/虚拟单元格(为了视觉效果),然后删除原始单元格,然后为副本设置动画,然后插入底部,最后删除重复/虚拟单元格。

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 2013-10-15
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多