ios - 如何在iOS中从TableView高度的底部到顶部插入动画的TableView行

标签 ios objective-c tableview

enter image description here

我需要插入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/

相关文章:

ios - 将数据从Parse.com类提取到NSArray中

ios - 使用 Aspect Fit 时如何去除图像中的空白区域?

ios - 自动布局:在不知道高度约束的情况下隐藏 UIView

ios - 如何将数据保存到一个 View Controller 中的 CoreData 中,然后让 tableview 在另一个 View Controller 中显示数据?

JavaFX、TableView 和 JPA

ios - ARKit + Core 位置 - 点不固定在同一个地方

ios - Facebook session 关闭

JavaFX 将组合框中的字符串字段显示为字符串的枚举(在 TableView 中)

iphone - 如何使用 "from-color"和 "to-color"创建具有垂直渐变的 UIImage

ios - 查找 view.subviews 中的所有按钮