我需要插入tableview单元格,它应该从tableview高度的底部滑动到顶部。我在按钮上调用以下代码。但它不是来自底部。
[array_messages addObject:message];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array_messages count]-1 inSection:0];
[self.tableViewMessage insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
答案 0 :(得分:2)
您可以使用以下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) {
}];
}
根据需要修改动画
答案 1 :(得分:2)
对于Swift 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)
}