2011-12-26 146 views
7

所以,當用戶點擊我的表格中的單元格時,我實際上並未推送到新的視圖控制器,我只是重新加載該tableView中的數據。重新加載表動畫

但是,如果我確實推送了新的視圖控制器,我想獲得類似於它的樣子的效果。

是否有人知道如何將舊內容從屏幕上移出舊內容並將新內容移動到整個表的屏幕上?

回答

13

取決於你有多少部分有可以使用- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

所以你可以做這樣的事情:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    [tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,[self numberOfSectionsInTableView])] withRowAnimation:UITableViewRowAnimationRight]; 
} 
+0

你是男人。看起來不完美,但我會玩。 – endy 2011-12-26 14:19:03

+0

它有什麼問題? – DanZimm 2011-12-26 14:58:35

+1

如果我用不同數量的部分加載數據,應用程序崩潰。我想我只是插入第二個tableview並將其滑過舊的。 – endy 2011-12-26 19:30:54

0

簡單的動畫

func animateTable() { 
    self.reloadData() 

    let cells = self.visibleCells 
    let tableHeight: CGFloat = self.bounds.size.height 

    for i in cells { 
     let cell: UITableViewCell = i as UITableViewCell 
     cell.transform = CGAffineTransform(translationX: 0, y: tableHeight) 
    } 

    var index = 0 

    for a in cells { 
     let cell: UITableViewCell = a as UITableViewCell 

     UIView.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveLinear, animations: { 
      cell.transform = CGAffineTransform.identity 
     }, completion: nil) 

     index += 1 
    } 
}