我可以在 UIView.animate 中使用 DiffableDataSource 动画吗?

问题描述

我在玩UITableViewDiffableDataSource, 并且我正在尝试在更改数据源时为此函数添加延迟和持续时间: open func apply(_ snapshot: NSDiffableDataSourceSnapshot<SectionIdentifierType,ItemIdentifierType>,animatingDifferences: Bool = true,completion: (() -> Void)? = nil)

我的代码:

        func didTapButton() {
            button.alpha = 0
            var diffableDataSourceSnapshot = self.snapshot()
            diffableDataSourceSnapshot.insertItems([newItem],afterItem: item)
            diffableDataSourceSnapshot.deleteItems([item])
                
            UIView.animate(withDuration: 1,delay: 3,options: []) {
                self.apply(diffableDataSourceSnapshot,animatingDifferences: true)
            } completion: { _ in
                self.view.layoutIfNeeded()
            }
    }

我想:

  1. 立即隐藏按钮
  2. 3 秒后,使用 diffableDataSourceSnapshot 函数更改视图。

然而,UIView 动画块似乎不起作用,我看到的是应用程序立即执行 diffableDataSourceSnapshot 动画,没有持续时间和延迟。

无论如何我可以在 UIView 动画块中使用“应用”功能?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)