ios - 快照 View (屏幕更新后 : true) returns an empty view

标签 ios swift uikit transition navigationcontroller

我想为导航 Controller 实现自定义推送转换。

我首先实现了 UINavigationControllerDelegate,我在其中返回了一个 UIViewControllerAnimatedTransitioning 的对象。

在这门课中,我想拍摄目标 View 的快照,以便为其设置动画。但是,对于推送序列,这不起作用 - 快照是空的。 [当我弹出时,我设置了 afterScreenUpdates = false 并且一切正常]

    guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
        let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) else {
            return
    }

    guard let snapshot = toVC.view.snapshotView(afterScreenUpdates: true) else {
        return }

   // Problem:
   // snapshot is an empty view!

最佳答案

为 -snapshotViewAfterScreenUpdates: 提供 true 意味着它需要回到运行循环才能实际绘制图像。如果您提供 NO,它会立即尝试,但如果您的 View 不在屏幕上或尚未绘制到屏幕上,则快照将为空。

关于ios - 快照 View (屏幕更新后 : true) returns an empty view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47024439/

相关文章:

ios - 带有图像的进度条

ios - 带有 Swift 的 CocoaPods 0.36 上的 GoogleAnalytics-iOS-SDK

ios - 静态 TableView 中单元格的内容未显示 SWIFT 3

android - iBeacons - 公司(Estimote、Gimbal 等)SDK 与 Android/iOS 库

iphone - 对象释放速度不够快,导致应用重新启动崩溃

iphone - 如何为我自己的按钮/导航栏项目使用尖头后退按钮?

swift - 无法使用 swift 3 从其数据源获取单元格

ios - 如何仅从 collectionView 的单元格中重新加载一项? swift 4

iOS Swift 3 如何在动画完成后执行 Action

ios - 如何知道 iOS 8 中的当前 interfaceOrientation?