0

我正在玩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 动画块中使用那个“应用”功能吗?

4

0 回答 0