2016-04-12 30 views
0

enter image description here如何插入的tableview行從的tableview高度的動畫底部到頂部在IOS

我需要插入的tableview細胞和top.I我打電話以下按鈕自來水代碼應該從實現代碼如下高度的底部滑動。但它不是來自底層。

[array_messages addObject:message]; 

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0]; 
[self.tableViewMessage insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom]; 
+0

添加一些代碼。 – iOS

回答

2

您可以使用以下UITableViewdataSource方法來指定動畫

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    let frame = cell.frame 
    cell.frame = CGRectMake(0, self.tableView.frame.height, frame.width, frame.height) 
    UIView.animateWithDuration(1.0, delay: 0.0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: {() -> Void in 
     cell.frame = frame 
    }, completion: nil) 
} 

在objc

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGRect frame = cell.frame 
    [cell setFrame:CGRectMake(0, self.tableView.frame.height, frame.width, frame.height)]; 
    [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 
     [cell setFrame:frame]; 
     } completion:^(BOOL finished) { 
    }]; 
} 

修改動畫,以滿足您的需要

+0

我需要這個在目標c中。 – DJtiwari

+0

新增了objC代碼 – Mathews

+0

我得到這個錯誤「沒有成員用struct CGRect中的寬度和高度命名」 – DJtiwari

2

對於斯威夫特3, Xcode 8.1

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    let frame = cell.frame 
    cell.frame = CGRect(x: 0, y: self.tableView.frame.height, width: frame.width, height: frame.height) 
    UIView.animate(withDuration: 1.0, delay: 0.0, options: UIViewAnimationOptions.transitionCrossDissolve, animations: {() -> Void in 
     cell.frame = frame 
    }, completion: nil) 

} 
相關問題