【问题标题】:Add UITableViewCells between 2 UITableviewCells in an UITableView with an animation在带有动画的 UITableView 中的 2 个 UITableviewCells 之间添加 UITableViewCells
【发布时间】:2013-02-19 06:17:56
【问题描述】:

现在我正在制作一个涉及UITableView 的 iPad 应用程序,其中涉及到左右滑动的UITableView Cells,我有一个基于NSNotification 的系统,让UITableViewController 知道何时发生滑动。我需要在移动的单元格下方和移动单元格下方的单元格上方显示UITableViewCell。我想做一个清晰的应用程序中看到的折叠动画,但没有pinch gesture(即自动折叠)。我找到了这个名为MPFoldTransition 的库。但是,它不支持UITableView。我还在这个tutorial 中查看了pinch gesture,但是本教程没有告诉我如何自动为动画制作动画,因为它需要用户进行捏合手势。我浏览了网络,似乎找不到任何东西。我将不胜感激。

谢谢

【问题讨论】:

  • “但是本教程使用 UITableViewCell 子类,我不能拥有它” 有什么特别的原因吗?
  • 原因是我需要立即销毁 UIView(即重新激活它)
  • @ACB 我想我理论上可以使用一个非常定制的 UITableViewCell,我很抱歉这个疏忽,我已经编辑了我的问题以反映这个变化

标签: ios uiview uitableview


【解决方案1】:

这完全可以使用MPFoldTransitiontransitionFromView: toView:...。我创建了一个示例项目,如果您愿意,我可以链接到该项目,但这一切都归结为:

- (void)addNewTableCellToIndexPath:(NSIndexPath *)indexPath {
    // Add the new object to the datasource and reload the row
    [dataSourceArray insertObject:@"New" atIndex:indexPath.row];

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

    //setup temporary cell
    UITableViewCell *fromCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    [fromCell setBackgroundColor:[[self.tableView cellForRowAtIndexPath:indexPath] backgroundColor]];
    //setup cell to animate to
    UITableViewCell *toCell = [self.tableView cellForRowAtIndexPath:indexPath];
    [toCell.textLabel setText:dataSourceArray[indexPath.row]];

    //add fold animation to the cells create above
    [MPFoldTransition transitionFromView:fromCell
                                  toView:toCell
                                duration:0.4
                                   style:MPFoldStyleUnfold
                        transitionAction:MPTransitionActionNone
                              completion:^(BOOL finished) {
                                  [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                              }];
}

About 是一个将索引路径作为参数的函数。将您希望添加具有折叠过渡的单元格的索引路径发送给它,它将在表格上创建一个空白临时单元格以进行折叠,同时将其余单元格向下移动。这并不完美,主要是因为我还没有想出办法将UITableViewRowAnimation 的持续时间更改为完美与折叠持续时间相匹配。

无论如何,这应该足以让您继续前进。希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 2015-04-20
    • 2015-05-07
    • 1970-01-01
    • 2022-01-27
    • 2016-04-02
    • 1970-01-01
    相关资源
    最近更新 更多