【问题标题】:UICollectionView performBatchUpdates completion not called while off screen关闭屏幕时未调用 UICollectionView performBatchUpdates 完成
【发布时间】:2016-10-19 16:58:38
【问题描述】:

我正在为我的视图控制器使用快照测试。这是视图控制器在测试中的初始化方式:

window.addSubview(viewController.view) // simulate the view is visible (probably unnecessary)
viewController.view.frame = self.snapshotFrame // set frame
viewController.beginAppearanceTransition(true, animated: false) // simulate VC's life cycle
viewController.endAppearanceTransition()

我的视图控制器包含 UICollectionView。当我使用 performBatchUpdates 执行集合视图更新时,即使更新块已完成,也永远不会调用完成。

// Animate udpates
self.collectionView.performBatchUpdates({
      // is called 
}, completion: { _ in
      // never called
})

我认为这与集合视图的屏幕外渲染有关。有人有类似问题的经验吗?我缺少什么来说服 UICollectionView 它在屏幕上?

【问题讨论】:

    标签: ios swift uicollectionview uikit fbsnapshottestcase


    【解决方案1】:

    我发现了问题。这一切都是关于一个适当的时机。在调用完成之前完成的测试用例并释放视图控制器。

    我通过设置加快了集合视图动画

    viewController.view.layer.speed = 100 // speed up animations
    

    并将测试用例的超时时间增加到 0.1 秒。现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 2015-03-05
      相关资源
      最近更新 更多