DJtiwari DJtiwari - 2 months ago 16
iOS Question

How to insert tableview row animate from bottom of tableview height to top in ios

enter image description here

I need to insert tableview cell and it should slide from bottom of tableview height to top.I am calling following code on button tap.But it is not coming from bottom.

[array_messages addObject:message];

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


you may use the following UITableView dataSource method to specify the animation

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)

In 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) {

Modify the animation to suit your need