【问题标题】:Uitableview Cell Animation like Secret AppUtableview Cell Animation like Secret App
【发布时间】:2014-08-11 18:44:19
【问题描述】:

任何想法,我该如何实施- Secret App 设置列表单元格动画。

我正在尝试这个,但没有任何成功,因为它同时添加了所有行。

[self.tableview reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationBottom];

如果我逐行插入,则此动画无法从下到上动画。

任何建议我该怎么做?

【问题讨论】:

  • 屏幕录像在这里很有价值。一是让我们不必去安装应用程序,二是为了让这个问题在 Secret 更改他们的应用程序后具有一定的历史价值。
  • 我会尝试添加 gif。谢谢 Chris。
  • 你可能需要在 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;中实现一些动画;

标签: ios objective-c uitableview animation


【解决方案1】:

试试这个实现:

//From UITableViewDelegate calls
- (void)tableView:(UITableView *)tableView
  willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath{
    CGRect myRect = [tableView rectForRowAtIndexPath:indexPath];

    //instead of 568, choose the origin of your animation
    cell.frame = CGRectMake(cell.frame.origin.x,
                            cell.frame.origin.y + 568,
                            cell.frame.size.width,
                            cell.frame.size.height);

    [UIView animateWithDuration:0.5 delay:0.1*indexPath.row options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //instead of -30, choose how much you want the cell to get "under" the cell above
        cell.frame = CGRectMake(myRect.origin.x,
                                myRect.origin.y - 30,
                                myRect.size.width,
                                myRect.size.height);

    } completion:^(BOOL finished){
        [UIView animateWithDuration:0.5 animations:^{
            cell.frame = myRect;
        }];

    }];
}

【讨论】:

  • 我在快速滚动时使用了此代码弹跳单元格。弹跳和弹跳问题不是正确的动画单元。我想在快速滚动中一一添加单元格。
  • 将延迟设置为 0 并更改持续时间(比如说:0.2)
  • 好的,谢谢,现在我只想要一个时间动画,当我滚动第二个时间表时我不想要动画,这可能吗?
  • 您可以尝试使用与数据源相同大小的 NSArray 并为那些已经出现的单元格设置一个值(布尔值?)。
【解决方案2】:

克劳迪奥的答案的 Swift-4 版本

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {


        let rect = tableView.rectForRow(at: indexPath)

        cell.frame = CGRect(x: cell.frame.origin.x,
                            y: cell.frame.origin.y + 568,
                            width: cell.frame.size.width,
                            height: cell.frame.size.height)

        UIView.animate(withDuration: 0.5, delay: 0.1*Double(indexPath.row), options: UIViewAnimationOptions.curveEaseInOut, animations: {
            cell.frame = CGRect(x: rect.origin.x,
                                y: rect.origin.y-30,
                                width: rect.width,
                                height: rect.height)
        }) { (completed) in
            UIView.animate(withDuration: 0.5, animations: {
                cell.frame = rect
            })
        }

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 2020-08-20
    • 2014-03-19
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多