使用动画在UITableView中的2个UITableviewCell之间添加UITableViewCells

vir*_*ndh 6 uitableview uiview ios

现在我正在制作一个UITableView涉及UITableView Cells左右滑动的iPad应用程序,我有一个NSNotification基础系统让玩家UITableViewController知道幻灯片何时出现.我需要UITableViewCell在移动的单元格下方以及移动单元格下方的单元格上方显示.我想做一个折叠动画,如应用程序清晰但没有pinch gesture(即自动折叠).我发现这个名为MPFoldTransition的库.但是,它不支持UITableView.我也在pinch gesture教程中进行了研究,但本教程并未告诉我如何自动动画动画,因为它需要用户进行捏合手势.我环顾网络,似乎无法找到任何东西.我将不胜感激任何帮助.

谢谢

Mic*_*lum 7

使用MPFoldTransition's 完全可以transitionFromView: 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];
                              }];
}
Run Code Online (Sandbox Code Playgroud)

About是一个将索引路径作为参数的函数.向它发送您希望添加具有折叠转换的单元格的索引路径,它将在表格上创建一个空白临时单元格以折叠,同时向下移动其余单元格.它并不完美,主要是因为我还没有找到一种方法来改变UITableViewRowAnimation持续时间以完全匹配折叠持续时间.

无论哪种方式,这应该足以让你前进.希望这可以帮助!