【问题标题】:display rows/cells in UITableview one by one with animation在 UITableview 中用动画一一显示行/单元格
【发布时间】:2015-06-06 10:36:45
【问题描述】:

我有一个表格视图,其中包含在情节提要的 ViewController 场景中设计的原型单元格。

现在我的目标是当应用程序启动并加载视图时,tableview 中的数据不应该立即出现,而是会随着动画一一出现。

这是我如何制作动画的代码:-

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (![shownIndexes containsObject:indexPath]) {
        [shownIndexes addObject:indexPath];
       [UIView animateWithDuration:2.0f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionAllowAnimatedContent animations:^{
            vw.frame = frame;
      } completion:^(BOOL finished) {

      }];
  }

其他方法:-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    return 1;    //count of section
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 20;    //count number of row from counting array hear cataGorry is An Array
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;

}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"CellA";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
 return cell;


}

下面的代码正在为最初在 tableview 中显示的前 5 个单元格设置动画,但之后当我滚动时它会一个一个地发生。

所以主要问题是

如何在UITableview中逐行显示行或单元格,而不是一次动画?

任何信息或帮助将不胜感激。

谢谢。

【问题讨论】:

  • 问题是什么?可能会更清楚
  • 如何在UITableview中逐一显示行或单元格,而不是一次动画? @omerio
  • 您可以增加 i 动画的延迟,例如第二个单元格为 2 秒,第三个单元格为 4 秒,以此类推,但正如您所见,这将花费很长时间,因此请确保您的用户不会在动画结束之前离开。
  • 你找到合适的答案了吗?

标签: ios objective-c iphone uitableview animation


【解决方案1】:

首先告诉表格in只有一行,在numberOfRows…。延迟后,返回 2 而不是 1。以此类推。

【讨论】:

  • 这真的是一个解决方案!您期望这将如何工作,您如何假设延迟 'numberOfRows' ,这意味着您必须调用重新加载表格视图,这肯定会再次为前一个单元格设置动画。
  • 您也可以使用 insert insertRowsAtIndexPaths:withRowAnimation:
  • 您可以在不重新加载整个表的情况下更改行数。阳光提出的是一种方式,也可以查看beginUpdatesendUpdates
猜你喜欢
  • 2012-02-29
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多