我需要插入tableview单元格,它应该从tableview高度的底部滑到顶部。我在按钮点击时调用以下代码,但是它不是从底部发出的。
[array_messages addObject:message];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0];
[self.tableViewMessage insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
最佳答案
您可以使用以下UITableView
dataSource
方法指定动画
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) {
}];
}
修改动画以适合您的需要
关于ios - 如何在iOS中从TableView高度的底部到顶部插入动画的TableView行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36570626/