【问题标题】:UITableViewRowAnimationNone - behaving as UITableViewRowAnimation(Top/Bottom)UITableViewRowAnimationNone - 表现得像 UITableViewRowAnimation(Top/Bottom)
【发布时间】:2015-05-11 08:45:29
【问题描述】:

我已使用以下代码设置行插入。我只在插入和删除行时使用UITableViewRowAnimationNone,但有时,正如您在下面的 gif 中看到的那样,行从顶部或底部动画。在大多数情况下,它不会像我想要的那样设置动画,但有时它会在插入和删除时设置动画。我不是在谈论扩展表格视图以显示插入的单元格,我的意思是单元格似乎从底部或顶部滑入。

下面是控制插入动画的方法:

- (void)contentHeaderFooterView:(NFContentHeaderFooterView *)headerFooterView sectionOpened:(NSInteger)section{

    NSIndexPath *pathToAdd = [NSIndexPath indexPathForRow:0 inSection:section];

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:@[pathToAdd] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

}

这里是控制删除动画的方法。

- (void)contentHeaderFooterView:(NFContentHeaderFooterView *)headerFooterView sectionClosed:(NSInteger)section{

    NSIndexPath *pathToDelete = [NSIndexPath indexPathForRow:0 inSection:section];

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:@[pathToDelete] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];

}

【问题讨论】:

  • 同样的问题,似乎是一个错误。

标签: ios uitableview uiview caanimation


【解决方案1】:

我遇到过类似的问题,表格更新没有执行我直接提供的动画。我不能确定为什么,但我可以建议的一件事是,不要在 begin/endUpdates 之间执行特定的行删除,您可以只使用硬 reloadData。

【讨论】:

    【解决方案2】:

    在这里回答:https://stackoverflow.com/a/37352789/577237

    因为简短,所以重新发布:

    [UIView performWithoutAnimation:^{
                        [self.tableView beginUpdates];
                        [self.tableView deleteRowsAtIndexPaths:rowsToRemove withRowAnimation:UITableViewRowAnimationNone];
                        [self.tableView endUpdates];
                    }];
    

    请注意,这是 iOS 7.0+

    【讨论】:

      猜你喜欢
      • 2012-11-24
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 2020-09-16
      • 2010-09-22
      • 2014-07-06
      • 2020-08-25
      相关资源
      最近更新 更多