现在我正在制作一个涉及 UITableView
的 iPad 应用程序,其中涉及左右滑动的 UITableView Cells
,我有一个 NSNotification
基于让 UITableViewController
知道何时发生幻灯片的系统。我需要在移动的单元格下方和移动单元格下方的单元格上方显示一个 UITableViewCell
。我想做一个折叠动画,如在应用程序中看到的那样清晰,但没有 pinch gesture
(即自动折叠)。我找到了这个名为 MPFoldTransition 的图书馆.但是,它不支持 UITableView
。我还研究了此 tutorial 中的捏合手势
,但是本教程没有告诉我如何自动制作动画,因为它需要用户做一个捏手势。我环顾了网络,似乎找不到任何东西。我将不胜感激任何帮助。
谢谢
最佳答案
这完全可以使用 MPFoldTransition
的 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];
}];
}
About 是一个将索引路径作为参数的函数。将您希望添加具有折叠过渡的单元格的索引路径发送给它,它将在表格上创建一个空白的临时单元格以折叠,同时将其余单元格向下移动。它并不完美,主要是因为我还没有想出一种方法来更改 UITableViewRowAnimation
的持续时间以完美匹配折叠持续时间。
无论哪种方式,这应该足以让您继续前进。希望这对您有所帮助!
关于ios - 在带有动画的 UITableView 中的 2 个 UITableviewCells 之间添加 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213778/