此使用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];
}];
}
的是一個函數,指數路徑作爲參數。將摺疊過渡發送給您希望添加單元格的索引路徑,並且它將在表格上創建一個空白臨時單元格以從其中摺疊起來,同時將剩下的單元格向下移動。這並不完美,主要是因爲我還沒有想出一個辦法來改變UITableViewRowAnimation
的持續時間爲完美與摺疊持續時間相匹配。
無論哪種方式,這應該足以讓你去。希望這可以幫助!
_「然而,本教程使用UITableViewCell子類,我不能有這個」_任何特定的原因呢? – iDev 2013-03-05 00:39:49
原因是我需要立即銷燬UIView(即重新生成它) – virindh 2013-03-05 01:11:44
@ACB我想我可以理論上使用一個非常定製的UITableViewCell,對不起這個疏忽,我編輯了我的問題來反映這個改變 – virindh 2013-03-07 17:43:15