2013-03-05 33 views
6

現在我做一個iPad應用程序,涉及到UITableView,涉及UITableView Cells是左右滑動,我有讓當幻燈片出現UITableViewController知道的NSNotification基礎的系統。我需要在已移動的單元格下方顯示一個UITableViewCell,並且在移動的單元格下方的單元格上方顯示一個UITableViewCell。我想做一個摺疊動畫,如在應用程序清除中看到的,但沒有pinch gesture(即自動摺疊)。我找到了這個名爲MPFoldTransition的圖書館。但是,它不支持UITableView。我也看過pinch gesture這個tutorial,但是本教程不告訴我如何自動動畫動畫,因爲它需要用戶做一個捏手勢。我環顧網絡,似乎找不到任何東西。我會感謝任何幫助。添加2個UITableviewCells之間UITableViewCells與動畫

由於

+1

_「然而,本教程使用UITableViewCell子類,我不能有這個」_任何特定的原因呢? – iDev 2013-03-05 00:39:49

+0

原因是我需要立即銷燬UIView(即重新生成它) – virindh 2013-03-05 01:11:44

+0

@ACB我想我可以理論上使用一個非常定製的UITableViewCell,對不起這個疏忽,我編輯了我的問題來反映這個改變 – virindh 2013-03-07 17:43:15

回答

7

此使用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]; 
           }]; 
} 

的是一個函數,指數路徑作爲參數。將摺疊過渡發送給您希望添加單元格的索引路徑,並且它將在表格上創建一個空白臨時單元格以從其中摺疊起來,同時將剩下的單元格向下移動。這並不完美,主要是因爲我還沒有想出一個辦法來改變UITableViewRowAnimation的持續時間爲完美與摺疊持續時間相匹配。

無論哪種方式,這應該足以讓你去。希望這可以幫助!